Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The extraction engine

For the curious: the full path a single extraction takes. You do not need this to run a review; see How AI extraction works for the short version.

End-to-end lifecycle

  1. You define the schema in the Variables editor (Protocol → Variables); it is saved to schema.yaml.

  2. The app compiles the schema to a tool definition. build_extraction_tool_schema() walks your fields into a JSON Schema: the {value, quote} envelope for leaves, arrays for lists and groups, enum for fixed options, and a _flag_check block for the inclusion re-check.

  3. The app assembles one request: the system prompt (with {{criteria}} and {{schema_md}} substituted), the tool definition, and the paper markdown as the user message. It sets tool_choice so the model must call the tool. A model that refuses a forced call is told in the system prompt to use the tool instead, and a reply without the call fails that paper, so nothing is parsed from prose.

  4. The model returns the tool call: a JSON object keyed by your field names.

  5. The app unwraps and stores it: one row per top-level field in the extractions table. Leaf values are unwrapped to (value, quote); objects and groups are stored whole, with their inner quotes preserved. The _flag_check is stored separately and also derives a full-text screening verdict.

  6. The verify queue renders the rows back into the form so a human can confirm or edit each value. Re-running a paper repeats steps 3 to 5 and re-types the previous run’s rows as superseded rather than deleting them, so an earlier version stays readable.

  7. Exports join the result with bibliographic metadata by source_id; the AI only ever extracted what the full text added.

The key property: steps 2–4 fix the structure independently of the prompt’s wording in step 3. The relevant code lives in extraction.py (schema → tool), reviewers.py (request + unwrap), tasks/extract.py (the loop), and core/database.py (storage).

What the prompt can and can’t change

The prompt can influenceThe prompt cannot change
where to look in the paper (e.g. “the Methods section”)which fields exist or their names
what counts as one item in a repeating groupthe type or shape of any field
when to leave a field null vs. guesswhether a value is paired with a quote
how to disambiguate confusable fieldsthe set of enum options

A weak prompt lowers quality, never validity. Improve recall and accuracy through the prompt; fix structure and option-sets in the schema.

Common problems

SymptomUsual causeFix
A field is null even though the paper states itthe model didn’t connect the paper text to the fieldsharpen the field description (the model reads it as the slot’s label); hint in the prompt where it appears
Values land in the wrong fieldtwo fields are easy to confusemake each description draw the boundary explicitly; consider an enum
Imported (external) results don’t show upkey names don’t match the schemathe importer matches by exact field name; align the JSON keys, or re-run inside the app where the structure is enforced
A paper comes back failed, with nothing storedthe tool-use JSON did not survive intact: usually truncated output on a long paper with many fields, or a structured field the model serialized as a JSON string that does not parsethe run summary now names the error and its type. The output cap is 16000 tokens, comfortably above a measured run, so repeated truncation means the schema is too large for one call; a failed paper is safe to re-run on its own from the Extraction page

A failure is deliberately all-or-nothing per paper: a half-parsed tool call would store some fields and silently drop others, which is worse than an obvious failure. What the model returned for each field is kept in raw_output alongside the unwrapped value, which is what makes a bare value distinguishable from a {value, quote} object after the fact.