Book

Python Programming for Social Workers
A Hands On Guide to Natural Language Processing and Large Language Models in Research and Practice
Nari Yoo. Under contract with Routledge, Skills for Social Work Practice series.

Social work agencies are starting to use AI tools for clinical documentation and case review, and social work researchers now analyze case records and public comments with natural language processing (NLP) and large language models (LLMs). This textbook teaches social work students, researchers, and practitioners to use these methods in Python. It assumes no programming background. The early chapters cover Python and the NLP methods that came before LLMs, since a social worker who knows how a program handles text is in a position to check what an LLM or a coding agent produces. Each chapter is built around a social work example in a Jupyter notebook, and privacy and professional ethics are covered before any method is taught. The book is intended for MSW and PhD courses and for practitioners whose agencies are considering AI tools.

DictionarymethodClassicalclassifierFine-tunedencoder (BERT)Local open-weight modelCommercialLLM via APIClient text can stay in your organizationSent to a vendor(data center)Lower cost, easier to inspectMore flexible, higher cost per record
Lower cost, easier to inspectDictionary methodClient text can stay in your organizationClassical classifierClient text can stay in your organizationFine-tuned encoder (BERT)Client text can stay in your organizationLocal open-weight modelClient text can stay in your organizationCommercial LLM via APISent to a vendor (data center)More flexible, higher cost per record

Contents

Part IFoundations1 Records as data2 Python basics3 Collecting text dataPart IIEthics andpre-LLM NLP4 Ethics and privacy5 Classic NLP6 Evaluation, fairnessPart IIILarge languagemodels7 Inside LLMs8 Prompts and APIs9 RAG and tool usePart IVApplications andtool building10 Applications11 Building toolsPart VCapstone12 Capstone project
Part I. Foundations
1Social Work Records as Data in the Age of AI

The chapter covers how social work records developed from Mary Richmond’s case records to electronic health records and the AI documentation tools agencies now consider. It introduces the book’s division between methods from before LLMs and current LLM methods, along with a question that recurs in later chapters, namely which method a task requires. The chapter closes with a first Jupyter notebook.

2Python Basics with Case Notes and Social Work Text

The chapter introduces variables and data types, loops for processing many records, functions, file handling, and version control, using case notes in a Jupyter notebook. It also covers writing and debugging code with an AI coding assistant and reviewing and testing the code such an assistant produces.

3Collecting and Cleaning Social Work Text Data

The chapter covers loading and cleaning case notes, open-ended survey responses, and public comments, and collecting public web data through APIs and web scraping within legal and ethical limits. It also addresses de-identification, missing and inconsistent records, and the construction of an annotation codebook. One exercise asks who decides what “positive sentiment” means for an involuntary client.

Part II. Ethics and Pre-LLM NLP Methods
4Ethics, Privacy, and Data Security in Social Work AI

The chapter turns the NASW Code of Ethics into decisions a person writing code has to make, with guidance from BASW, the Ontario College of Social Workers and Social Service Workers, and the IFSW alongside. It covers de-identification, Indigenous data sovereignty, review of vendor terms, and HIPAA next to comparable laws in the EU, the UK, Canada, and Australia. The chapter produces an ethics checklist and a data handling log that are applied in every later notebook.

5Topic Modeling, Sentiment Analysis, and Classic NLP

The chapter presents the standard methods from before LLMs, including preprocessing that handles clinical abbreviations, dictionaries, bag of words and TF-IDF, topic models of client feedback, sentiment analysis of public comments, and named entity recognition on case notes. Each output is checked against the original documents. These methods are often cheaper and easier to inspect than an LLM, and they prepare the comparison in Chapter 8.

6Model Evaluation, Fairness, and Explainable AI

A classifier is evaluated on labeled social work text with accuracy, precision, recall, F1, and subgroup analyses. A worked example shows a model with 95% overall accuracy and 0% accuracy for a small marginalized group. The chapter also discusses competing definitions of fairness and uses feature weights, SHAP, and LIME to examine why a model made a prediction.

Part III. Large Language Models
7Inside Large Language Models and Transformers

The chapter opens with the ethical questions specific to LLMs, such as sending client text to a commercial model, consent, environmental cost, and dependence on a few vendors. It explains transformers through diagrams, separates encoder models like BERT from generative models, and covers long context windows, reasoning models, and small open-weight models. A small open-weight model loaded in a notebook is used to examine tokens, context limits, and output.

8Prompt Engineering, APIs, and Choosing a Method

The chapter begins with automation bias and human oversight in high-stakes decisions. It covers calling LLMs from Python with zero-shot and few-shot prompts and with prompts that request intermediate reasoning steps. Batch processing of thousands of records is covered together with structured output and a log of every prompt and its cost. The same texts are then coded with a dictionary, a classical classifier, a fine-tuned encoder, a local open-weight model, and a commercial LLM, and compared on accuracy, cost, transparency, and privacy.

9Connecting LLMs to Documents with RAG and Tool Use

The chapter covers grounding a model’s answers in agency documents and compares placing documents in a long context window, retrieval-augmented generation, and allowing the model to search on its own. It then introduces functions that a model can call to query a database or complete a form. Every answer is checked against its sources, with attention to which records an LLM may read and which actions need human approval.

Part IV. Applications and Tool Building
10LLM Applications for Social Work Practice and Research

The chapter presents projects of the kind agencies and researchers are adopting, including help with clinical documentation, a resource navigation assistant, analysis of legislative testimony, coding open-ended survey responses at scale, analysis of scanned documents and audio with multimodal models, and a resource hub built from policy and service documents. Each project comes with code, an evaluation against human judgment, and the risks to review before deployment.

11Building Social Work Tools with AI Coding Agents

The chapter covers building tools for an agency or a study with Claude Code and Codex by describing the task, approving the agent’s plan, executing the code, and checking the result. The projects are an AI interviewer, an interactive dashboard, and a project website. The chapter also covers interface design for clients and staff with limited digital access, and the documentation and shared administration a tool needs after its builder leaves.

Part V. Capstone
12Evaluating, Deploying, and Maintaining an AI Project

The capstone is a complete project that starts from a research question or an agency workflow, selects a method using the Chapter 8 comparison, builds and evaluates it against human coding, documents its data handling, decides whether it should be used, and plans its handover. The chapter also covers participatory review with clients and communities and accountability when a system causes harm.

Seven appendices cover a Python quick reference, working with APIs, data cleaning for social work text, evaluation metrics, model selection, a privacy and security checklist, and a glossary.

Companion materials

  • Code and sample datasets (synthetic case notes and public policy documents) in a public GitHub repository
  • A Python Jupyter notebook for each chapter, updated as model names, prices, and API syntax change
  • Instructor resources with syllabi, coding assignments and solution notebooks, rubrics, and a test bank