top of page

How to code open-ended survey responses with Claude and a codebook

10 minutes ago
10 min read
Cover with the title How to code open-ended survey responses with Claude and a codebook over a teal city skyline, Data Studios original cover

Coding open-ended survey responses means assigning each free-text answer to one or more themes from a fixed list, so that comments such as "the dashboard is slow" and "loading times out" end up counted under the same heading. Claude can do this work on a CSV file when its code execution and file creation feature is turned on, and Anthropic's help center lists that feature for the Free, Pro, Max, Ultra, Team and Enterprise plans on the web, Claude Desktop and Claude Mobile. The result is only as good as the codebook you give it and the sample you check by hand afterward.


The method below keeps the analyst in charge of the themes. You write a codebook with definitions and examples, ask Claude to apply it to every row and return a coded file, then compare its codes with a human-coded sample using a short pandas script that reports per-code agreement and Cohen's kappa. The worked example uses twelve illustrative responses to a dashboard feedback question, with the correct theme counts computed in Python so you can compare them with whatever Claude returns.


Survey coding differs from sentiment labeling because one answer often carries two or three themes at once. In the example, five of the twelve responses need two codes, which produces 17 code assignments across 12 rows. Most errors in AI-assisted coding appear in exactly those multi-theme answers.


··········


WHEN ANALYSTS NEED TO CODE OPEN-ENDED SURVEY RESPONSES.


Product, HR and customer research teams usually collect a few hundred or a few thousand comments alongside rating questions. The ratings go straight into a dashboard, while the comments stay unread until someone turns them into counts. Coding converts that text into a categorical column that can be filtered, cross-tabulated against the rating scores and tracked from one survey wave to the next.


Two approaches exist. Inductive coding builds the theme list from the responses themselves, which suits a first survey on a new topic. Deductive coding applies a codebook that already exists, which suits recurring surveys where the numbers must stay comparable between waves. Claude can help with both, but the deductive approach is easier to verify, because every code has a written definition that a human reviewer can test against the AI's choices. A sensible routine is to let Claude propose candidate themes from a sample, edit them into a codebook yourself, and then use that fixed codebook for the full file.


The same discipline applies to the related task of scoring tone, covered in the Data Studios guide on how to classify review sentiment with Claude and check the labels. Survey coding adds the multi-label problem and the need for an "uncodable" category.


··········


CLAUDE FILE ANALYSIS REQUIREMENTS FOR SURVEY CODING.


Anthropic documents the relevant limits on two help center pages, both read on November 27, 2026. The "Create and edit files with Claude" article describes the private, sandboxed computing environment in which Claude writes and runs code such as Python, and states that you can upload CSV, TSV and other files for data analysis. The "Upload files to Claude" article, dated July 23, 2026, lists CSV, TXT, JSON and XLSX among the supported document types, with the note that XLSX uploads require code execution and file creation to be enabled.


........


Item

What Anthropic documents

Plans with code execution and file creation

Free, Pro, Max, Ultra, Team, Enterprise

Where it runs

Web, Claude Desktop, Claude Mobile

File size, code execution article

30 MB per file for uploads and downloads

File size, chat upload article

500 MB per file, up to 20 files per chat

Project knowledge files

30 MB per file, text extraction only

Personal setting

Settings > Capabilities, "Create and edit files"

Organization setting

Organization settings > Capabilities, "Code execution and file creation"

Usage

File creation uses more of your limit than normal chats


........


The two pages give different per-file sizes, so the safe working rule is to keep each survey export under 30 MB, which satisfies both. A CSV with a respondent ID and a comment column stays far below that size even with tens of thousands of rows. Team and Enterprise owners can disable the feature for the organization and control network egress for the sandbox; on Enterprise, network egress is off by default for new organizations, which does not affect coding a file you upload. Neither page publishes a row limit, a list of preinstalled Python packages or a retention period for files processed in the sandbox, so treat those points as undisclosed.


For teams that want the same task inside a spreadsheet or a warehouse, the alternatives are covered in the guides on how to categorize text with Fill with Gemini in Google Sheets and how to classify text in SQL with Snowflake Cortex AI_CLASSIFY.


··········


WRITING THE SURVEY CODEBOOK BEFORE YOU PROMPT CLAUDE.


A codebook for AI coding needs four elements per code: a short label in capitals, a one-sentence definition, an inclusion example and an exclusion rule that separates it from the nearest neighbor. It also needs two catch-all codes. NONE covers answers that state no improvement, and OTHER covers a real suggestion that fits no defined theme. Without them the model tends to force every answer into the closest real theme, which inflates the counts you care about.


The illustrative codebook for a question asking "What is one thing we could improve about the sales dashboard?" has five substantive codes. SPEED covers load times and timeouts. FRESHNESS covers data that is out of date or refreshed too rarely. FILTERS covers finding pages, filters and navigation. EXPORT covers getting data or charts out of the dashboard. TRAINING covers documentation, metric definitions and onboarding. A timeout caused by selecting a filter value gets both SPEED and FILTERS, and that rule is written into the codebook so the model and the human reviewer apply it the same way.


You are coding open-ended survey responses. Use ONLY the codebook below.

Codebook:
SPEED: slow loading, timeouts, long waits.
FRESHNESS: data out of date, refresh frequency, stale numbers.
FILTERS: finding filters, pages or navigation; filter behavior.
EXPORT: downloading or exporting data, tables or charts.
TRAINING: documentation, metric definitions, onboarding help.
OTHER: a concrete suggestion that fits none of the codes above.
NONE: no improvement requested.

Rules:
1. A response may receive several codes. Separate them with a semicolon.
2. Use NONE and OTHER only on their own, never combined with other codes.
3. If a slowdown is caused by a filter selection, assign SPEED;FILTERS.
4. Do not invent new codes. If unsure, choose the closest code and set
   flag = 1.

Read survey.csv (columns: id, response). Return claude_codes.csv with the
columns id, codes, flag, and a one-line reason for each row. Then print a
table with the number of responses per code and the percentage of all
responses.

Asking for a reason column and a flag gives the reviewer something to scan. Rows with flag set to 1 are the first ones to read by hand, and the reasons expose cases where the model coded a word rather than a meaning, for example tagging "export" because a respondent mentioned the export team.


··········


WORKED EXAMPLE: TWELVE ILLUSTRATIVE SURVEY RESPONSES.


The responses below are illustrative and were written for this example. The codes column is the reference coding, which is the answer a careful human coder would give with the codebook above.


........


id

Response

Reference codes

1

The sales dashboard takes almost a minute to load on Monday mornings.

SPEED

2

Numbers are a day behind, so I still check the CRM before calls.

FRESHNESS

3

I can't find the region filter and exporting to CSV cuts off rows.

FILTERS;EXPORT

4

Slow, and the data was stale again last week.

SPEED;FRESHNESS

5

A short video on how the margin metric is calculated would help.

TRAINING

6

Please let me export the chart with the filters I applied.

FILTERS;EXPORT

7

Nothing really, it works fine for me.

NONE

8

New hires don't know which page to start from.

TRAINING;FILTERS

9

Refresh it more often than once a day.

FRESHNESS

10

Loading the product page times out when I pick all stores.

SPEED;FILTERS

11

A spreadsheet download would save me copying the table by hand.

EXPORT

12

Add dark mode.

OTHER


........


Counting each response once per code, the correct summary computed in pandas is the table below. Percentages use the 12 responses as the base, so they add up to more than 100 percent because of the multi-coded rows.


........


Code

Responses

Share of responses

FILTERS

4

33.3%

EXPORT

3

25.0%

FRESHNESS

3

25.0%

SPEED

3

25.0%

TRAINING

2

16.7%

OTHER

1

8.3%

NONE

1

8.3%


........


If Claude's summary for this file shows FILTERS at 2 or 3, it has most likely dropped the second code on row 6, row 8 or row 10, where the navigation theme sits behind a more visible export, training or speed complaint. If percentages add up to exactly 100, the model has coded each row only once or used the code assignments, 17 in this case, as the denominator. Both errors change the ranking of themes that a product team would act on.


··········


CHECKING CLAUDE'S SURVEY CODES AGAINST A HUMAN SAMPLE.


For a real survey, code a random sample by hand before you look at Claude's output, then compare the two files. Simple percent agreement flatters rare codes, because a model that never assigns OTHER still agrees on every row where OTHER is absent. Cohen's kappa corrects for that chance agreement, and computing it per code shows which definitions need work. The script below was run locally on the twelve reference rows and on a test file built to contain three typical mistakes, a missed EXPORT on row 3, a missed FILTERS on row 8 and NONE instead of OTHER on row 12. The test file is a constructed check of the script, not output observed from Claude.


import pandas as pd

CODES = ["SPEED", "FRESHNESS", "FILTERS", "EXPORT", "TRAINING", "OTHER", "NONE"]

human = pd.read_csv("human_sample.csv")    # columns: id, codes
model = pd.read_csv("claude_codes.csv")    # columns: id, codes
m = human.merge(model, on="id", suffixes=("_h", "_c"))

def to_set(s):
    return set(str(s).split(";"))

rows = []
for code in CODES:
    h = m["codes_h"].map(lambda s: code in to_set(s))
    c = m["codes_c"].map(lambda s: code in to_set(s))
    p_o = (h == c).mean()
    p_e = h.mean() * c.mean() + (1 - h.mean()) * (1 - c.mean())
    kappa = (p_o - p_e) / (1 - p_e) if p_e < 1 else 1.0
    rows.append({"code": code, "human": int(h.sum()), "claude": int(c.sum()),
                 "agree_pct": round(100 * p_o, 1), "kappa": round(kappa, 2)})
print(pd.DataFrame(rows).to_string(index=False))

exact = (m["codes_h"].map(to_set) == m["codes_c"].map(to_set)).mean()
print("exact match of the full code set:", round(100 * exact, 1), "%")

On the test file the script returns the following per-code results.


........


Code

Human

Test file

Agreement

Kappa

SPEED

3

3

100.0%

1.00

FRESHNESS

3

3

100.0%

1.00

FILTERS

4

3

91.7%

0.80

EXPORT

3

2

91.7%

0.75

TRAINING

2

2

100.0%

1.00

OTHER

1

0

91.7%

0.00

NONE

1

2

91.7%

0.62


........


Every code shows at least 91.7 percent agreement, yet OTHER has a kappa of 0.00 and only 75.0 percent of rows match on the full code set. That gap is the reason to report kappa per code. A low kappa on a catch-all code usually means the codebook definition of NONE and OTHER is too vague; a low kappa on a substantive code usually means the model is dropping the second theme in multi-coded answers. Fix the definition or add an example, rerun on the same sample, and only then code the full file.


··········


WHAT CLAUDE TYPICALLY GETS WRONG IN SURVEY CODING.


The common failure modes follow from the task itself. Multi-theme answers lose their secondary code. Short answers such as "slow" or "fine" get coded by keyword without context. New codes appear in the output when the model finds a theme it considers important, even when the prompt forbids it, so the review script should reject any code outside the codebook list. Sarcasm and negation ("the export works great, when it works") are read literally. On long files, the coding rules can drift if the work is split across several turns, so ask Claude to apply the codebook in a single Python pass over the whole file and keep the prompt and codebook unchanged between survey waves.


The human checks stay the same for every survey. Code a random sample of at least a few dozen responses yourself before seeing the AI output, compare per code with kappa, read every flagged row and every row coded OTHER, and confirm that the summary table uses the number of responses as its denominator. Theme counts that feed a roadmap or an HR action plan should be signed off by the analyst who owns the survey. Background on how Claude reads spreadsheets and CSV files is in the Data Studios article on Claude spreadsheet uploading and data analysis features.


··········


SURVEY DATA PRIVACY WHEN CODING WITH CLAUDE.


Open-ended answers often contain names, email addresses and details that identify a respondent, so remove or mask direct identifiers before the upload and keep only the respondent ID and the comment column. Anthropic's code execution article states that sandbox environments are never shared between users, and it warns that content inside external files or websites can carry hidden instructions that try to make Claude run untrusted code or send data to third parties. A survey comment field is external text of exactly that kind, so review the output file rather than trusting it blindly.


On Team and Enterprise plans, owners decide whether code execution is available and which network destinations the sandbox can reach. The same article notes that connectors and MCP integrations can still send data regardless of the network egress setting, a point to check when the survey file arrives through a connected app rather than a direct upload. Neither help page states how long uploaded files are retained, so check your organization's agreement with Anthropic before uploading responses covered by an employee or customer confidentiality promise.


··········


CLAUDE SURVEY CODING: WHAT THE DOCUMENTATION CONFIRMS AND WHAT YOU MUST TEST.


Anthropic confirms that Claude can run Python on uploaded CSV and XLSX files on every current plan, within a 30 MB per-file limit for code execution, with organization owners able to switch the feature off and restrict network access. It does not publish a row limit, a package list or a file retention period on the pages that describe the feature, and the two help articles disagree on the maximum upload size, so a large survey should be tested before a deadline.


The coding quality depends on your codebook and your checks. A written definition and an exclusion rule for every code, explicit NONE and OTHER categories, a rule for multi-theme answers and a human-coded sample scored with per-code kappa turn Claude's output into numbers you can defend. In the illustrative file, the correct ranking puts FILTERS first with 4 of 12 responses, and a model that misses the navigation theme in a single multi-coded answer would leave it tied at 3 with three other themes.


··········


FOLLOW US FOR MORE.


·····


DATA STUDIOS


·····


datastudios.org


bottom of page