Evolving Executable Codebooks for Qualitative Coding

Qualitative researchers turn interviews, survey answers and news articles into themes using a codebook: a list of codes, each with a prose definition such as "the respondent expresses distrust of automated tools." Coders, human or machine, then apply those definitions to text. The definitions are the weak point. Two careful experts reading the same definition often disagree; one study measured agreement on inductive coding at Krippendorff's $\alpha = 0.2$. LLMs inherit the problem in a different form. They code literal, surface-level passages well but fall behind human experts on abstract or subtle ones. We propose to rewrite a code's definition as a short program that asks an LLM only narrow, literal yes/no questions and combines the answers with explicit logic. The program is found by evolutionary search in which an LLM edits candidate programs, as in FunSearch-style program discovery.

The bet is that an abstract code such as "frames immigration as an economic threat" can be broken into literal checks the model handles reliably. Examples are "does the passage mention jobs or wages?", "is the speaker attributing harm to immigrants?" and "is the claim asserted rather than reported?". The combination logic is then made explicit, so it can be inspected, rerun and edited. The result is a codebook that another lab can execute with a different model and get the same answers. A researcher can also read it and point to the exact clause they disagree with.

Core Claim

Representing each code as an evolved program over literal LLM predicates (yes/no questions about a passage) will narrow the gap between LLMs and experts on complex passages. It will also make coding more reproducible across seeds and models than applying a prose codebook directly. Both effects should hold when the comparison is matched for labeled data and for LLM calls. The program representation, not the evolutionary search alone, should carry the gain. We test that directly by evolving prose codebooks with the same loop and the same fitness.

Where This Sits in Prior Work

Two strands motivate the gap.

Text Annotation via Inductive Coding compares LLMs with human coders and finds a "complexity flip": LLMs win on simple segments and lose on complex ones. The same paper reports inter-coder $\alpha = 0.2$ and finds that fine-tuning plateaus near 100 examples. Our proposal targets that crossover. We do not ask the model to judge abstractions directly; we ask it only the literal sub-questions it is good at.

Automating Qualitative Data Analysis with LLMs fine-tunes with LoRA (low-rank adapter tuning) to imitate a coder's style. It reports GPT-4 agreement of Cohen's $\kappa$ 0.54–0.62 and argues that topic models miss subtext. We keep its premise that meaning lies beyond word co-occurrence. We differ in producing an inspectable decision procedure instead of adapted weights.

Three lines of LLM-assisted thematic analysis all keep the codebook as text. LLM-in-the-loop negotiates a prose codebook with a human through conversation and reaches $\kappa = 0.81$ on a password-manager survey. HICode labels segments and then clusters the labels into themes in a single forward pass. Multi-LLM Thematic Analysis with Dual Reliability Metrics samples independent runs and keeps the themes that recur. None of these selects, mutates or recombines codebook candidates against a measured objective. None turns definitions into something executable.

We borrow the reliability metrics from the third paper, Cohen's $\kappa$ plus embedding similarity. We use them as one term of a fitness function rather than as a final report.

The method comes from semantic code evolution.

FunSearch evolves only a small decision function inside a fixed skeleton and scores it with an automatic evaluator. Our skeleton is "segment in, code assignments out." The evolved part is the per-code logic.

MEoH searches for heuristics that trade off several goals at once. It keeps the candidates that no other candidate beats on every goal (a Pareto front) and adds a code-dissimilarity filter to prevent collapse into near-duplicates. We reuse both ideas. Our trade-off is agreement versus cost (predicate calls per segment) versus program size.

EvoPrompting shows that LLM crossover of code works when the evaluator is noisy but graded.

One finding constrains our design. FunSearch and MEoH both note that evolution stalls on sparse pass/fail signals. Per-code $\kappa$ on a development set is graded, so it suits this loop. Unlike FunSearch's exact verifiers, though, our evaluator rests on contested human labels. We confront this in the lens experiment below rather than assume a single ground truth.

Research Program

Program form. A codebook program contains one function per code. Each function can call a fixed set of primitives:

  • ask(segment, question), which asks a fixed small LLM a yes/no question at temperature zero and caches the answer;
  • keyword and regex matching;
  • embedding similarity to anchor phrases;
  • Boolean and weighted-threshold logic.

The questions themselves are part of what evolves. This keeps the program honest: any nuance must pass through a literal question whose text a researcher can read.

Search loop. We seed the population from the prose codebook, using an LLM to translate each definition into a first program. Larger LLM operators then perform two kinds of edits:

  • mutation, which rewrites a code's function after being shown its false positives and false negatives on the development set;
  • crossover, which merges two parents' functions for the same code.

Selection follows MEoH. Candidates are kept on the Pareto front of three objectives: development-set $\kappa$ against expert labels, mean ask calls per segment, and program length. Code-distance dissimilarity is used to preserve diversity, and populations are kept on separate islands as in FunSearch.

A fourth objective guards against programs that merely overfit one model's quirks. It is cross-backend stability: the agreement between the program's outputs when its ask calls are answered by two different predicate models. Final reporting uses a held-out test set that the search never sees.

Analysis. Besides accuracy, we study what the evolved programs contain. We measure how many predicates an abstract code needs. We check whether the predicates match how experts justify their codes, which we collect as short free-text rationales on a sample. We also test whether a researcher editing one predicate can fix a class of errors without side effects elsewhere.

Baselines

The naive reference point is the original prose codebook applied zero-shot by the predicate model, one call per code per segment. It is what a researcher gets for free. Any useful method must beat it, especially on complex segments.

The strongest existing competitor is a large LLM applying the prose codebook with chain-of-thought and few-shot examples drawn from the same labeled development set, in the style of the LLM-in-the-loop machine coder. On the Password Manager data that paper reports $\kappa = 0.81$ between human and LLM coding, against a human-to-human $\kappa = 0.77$. On the 1,000 code-quote dataset, Text Annotation via Inductive Coding reports a fine-tuned Falcon-7B BERTScore of 0.7642. We run the strongest baseline with the larger operator model, so it gets the stronger model while our programs use the small predicate model. We give it the identical development labels and tune its prompt over the same number of LLM calls the evolutionary search consumes.

Beating it means two things. First, a statistically significant $\kappa$ improvement on the complex-segment stratum of the test set. Second, no loss on the simple stratum, at equal or lower inference cost per segment. Matching it overall while being cheaper and more stable across models would be a weaker but still useful result. We would report it as such.

The supervised competitor is a LoRA-tuned open model trained on the same development labels, following Automating Qualitative Data Analysis with LLMs.

The ablation that isolates our key ingredient is an evolved prose codebook. The same loop, operators, fitness and call budget mutate and recombine the natural-language definitions, which the predicate model then applies directly. If this matches the program version, the contribution is evolutionary codebook search, not executable decomposition.

A second ablation removes ask, leaving only regex and embedding primitives. It measures how much the literal LLM questions contribute.

Why not just…?

Why not just prompt a strong LLM with the codebook? It is the default, and on literal data it already works: LLM-in-the-loop reaches $\kappa = 0.81$ on survey responses. The evidence against it is specific to hard cases. Text Annotation via Inductive Coding shows LLMs losing to experts on complex segments, and reports erratic few-shot curves for some models. Prompting also gives no explicit object to audit or transfer. Our complexity-stratified comparison and the cross-backend rerun settle whether decomposition helps or whether a strong prompted model already covers it. If prompting wins on the complex stratum, the core claim is false.

Why not just fine-tune with LoRA? Fine-tuning plateaus around 100 examples (Text Annotation via Inductive Coding). It also produces weights that cannot explain why a passage got a code, which matters when methods sections must justify coding decisions. We include it at equal labels because, on large labeled corpora like the Media Frames Corpus, it may well win on raw accuracy. If it does, our claim narrows to settings with few labels and to auditability and transfer.

Why not just optimize the prose codebook with the same evolutionary loop? This is the most serious threat, because it keeps the search and drops the programs. Nothing in the file shows it fails. It is our main ablation, and if it ties the program version we will say the program representation is unnecessary. The case for programs rests on two predictions we can check. The first is cross-model stability: a program's literal questions should transfer between predicate models better than prose. The second is cross-issue transfer, described below.

Why not just use topic models or HICode-style clustering? These discover themes but do not apply a fixed codebook reproducibly. Automating Qualitative Data Analysis with LLMs documents the gap between keyword co-occurrence and subtext. HICode addresses discovery (precision 0.72, recall 0.74 on Astro Queries), not consistent application. We treat them as complementary: HICode output can seed the initial codes our search operationalizes.

Proposed Experiments

Main benchmark: the Media Frames Corpus. The Media Frames Corpus covers more than 20,000 articles across three issues, annotated with 15 abstract framing dimensions by multiple annotators. We evolve programs at the passage level on immigration, using a few hundred labeled passages, and test on held-out immigration passages. Our frame-classification baselines are run by us; no reported frame-classification accuracy found on Lacuna for MFC.

Cross-issue transfer. Apply the immigration-evolved programs unchanged to smoking and same-sex marriage. Frames are issue-agnostic, so a program that captured the concept rather than surface cues should transfer better than an evolved prose codebook or the LoRA model.

Complexity stratification. On the 1,000 code-quote dataset from Text Annotation via Inductive Coding, we split segments by complexity, following that paper's distinction where its labels allow and otherwise using two expert raters. The test is whether the complexity flip shrinks under program coding.

Small-data realism. On the Password Manager data we develop on the same 100 responses LLM-in-the-loop used and test on the remaining 180. The bar there is $\kappa = 0.81$.

Interpretive lenses. Expert disagreement may reflect different valid readings rather than noise. To test this, we evolve a separate program per MFC annotator and diff the programs to locate the predicates where readings diverge. Annotators then judge whether the diffs describe their actual disagreement. This turns the reflexive-analysis view that coder subjectivity is meaningful into something checkable.

Decisive checks. Three outcomes would decide the proposal:

  • a significant complex-stratum $\kappa$ gain over the strongest prompted baseline at matched inference cost;
  • the program version beating the evolved-prose ablation on cross-backend stability and cross-issue transfer;
  • a blinded study in which qualitative researchers correct an error class faster and more precisely by editing a program than by editing a prose definition.

Failing the first two would mean executable codebooks buy auditability at best, and we would report exactly that.