Extraction
An Extract Fields step reads named, typed values out of text and up to four images. You list the fields you want. Each field comes back as a value of its declared type, or as null when the input doesn’t contain it. Every answer also carries the evidence a Flow needs to act on it: a confidence, the source span for text, and a calibrated range for an estimate.
An extraction model is not a chat model. There is no prompt, it generates no tokens, and it can’t return a value of the wrong type. Use it when a message, email, form, CSV, or photographed receipt holds values that a Record, a branch, or a later step needs.
Choose extraction, a judgment, or a prompt step
The three model-backed steps answer different kinds of question. Pick by the shape of the output you need:
Extraction returns the value. A judgment makes the decision. A prompt step writes the words. The three compose in that order: extract the facts, judge what to do, then write the reply. Only the rows that need a large model reach one.
A prompt step with Response Format set to JSON can also pull fields out of text. It is slower, it is billed on output tokens, and it doesn’t tell you whether a value was in the input or how sure the model is. Use an extract step when the field list is fixed.
What an extraction model can do
One extract step can mix four kinds of field. Each kind answers a different question about the input.
- Extract a value that is written down. A
textfield returns the exact characters from the input, with their position as aspan. Adatefield returns an ISO date even when the input writes “Sept 28”. - Compute a value that is not written down. A
numberfield with the instruction “Item price plus tax” returns the sum. Adurationfield returns the days between two dates. Keep each computation to one or two operations. Do longer arithmetic in a Run Code step. - Estimate a value with a range. An
estimatefield returns a point value and the 10th and 90th percentiles, for example a sale price from a table of comparable sales. The range is the signal: a wide range means thin evidence. - Forecast a series. A
forecastfield returns one estimate per future period, for a horizon of 1 to 64 periods, from the history in the input.
When the input doesn’t determine a field, the answer is null, not a guess. A list with no matches comes back as an empty array.
Worked example: read a support email
A customer sends this email to a Flow, which receives it as message:
The following extract step asks for six fields:
Each field shows a different behavior:
order_idanddelivered_onare read from the text.amount_paidis computed: 649.00 plus 52.10 is 701.10. The instruction asks for the computation.days_since_deliveryis computed from two dates in the email: 11 days.damageis a list of two spans of the text.tracking_numberisnull, because the email has none.
The step writes one object to claim. The following output shows its shape. The confidence and span values are illustrative:
The output has two halves:
valuesis a flat map with one entry per field. It is the object that a Record stores.answerskeeps the evidence for each field. A branch reads it. The sample shows three of the six answers.
Route on null and confidence, then store
Decide what to do with uncertain rows before you write anything. Store a claim only when its key fields are present and confident. Send the others to a person.
The following steps follow the extract step. The conditional sends a claim to review when its order ID is missing or its amount is not confident. Otherwise, the Flow stores the claim:
Four details in this pattern matter:
- Write conditions with bare variable paths, such as
claim.answers.tracking_number.value === null. A{{...}}reference is replaced with text before the condition runs, so it can’t compare againstnull. - Write
!(confidence >= 0.9), notconfidence < 0.9. An answer can omitconfidence. The negated form sends a missing confidence to review. The< 0.9form lets it through. - Set
sourceVariableto the pathclaim.values, not{{claim.values}}. Upsert Record reads the source as a variable path and doesn’t substitute templates. Validation reports a template there asUPSERT_SOURCE_TEMPLATE. - Key the Record on a value you routed on. Without a
recordName, each run creates a Record. Anullorder ID would give the Record an unusable name, which is why the condition checks it first.
The default Merge strategy writes every top-level key in values, including null ones. A null therefore replaces a value that an earlier run stored. To keep stored values, add a Run Code step that drops the null entries, and point sourceVariable at its output. For more about merge strategies, see Using record steps.
To choose between refund and repair, add a judgment in the store branch and pass it the extracted values as its state. Then add a prompt step that writes the reply from the decision and the facts.
The 0.9 threshold is a placeholder. Measure confidence against labeled examples from your own data before a threshold acts without review. The action policy stays in the Flow, not in the model.
Add an extract step in the dashboard
To add an extract step, follow these steps:
- Open the Flow and add an Extract Fields step.
- In Text to read, reference the text, for example
{{message}}. Text answers are spans of this text, so pass the whole message or document, not a summary. - Under Fields, click Add field for each field. Enter a name, pick a type, and add instructions when the name alone is ambiguous or you want a computation.
- In Writes to, enter the output variable. Later steps read the result from it.
- Optional: Pick a different model in the step settings, or expand Images, reference date to add images or set the date that “today” means.
The field name is sent to the model, so a descriptive name such as order_id is a complete field. A one- or two-character name with no instructions tells the model nothing, and validation recommends a better one.
Field types
The following table lists each type, what it returns, and the options it accepts:
Every field also accepts instructions and nullThreshold. nullThreshold is a number greater than 0 and at most 1, with a default of 0.5. A scalar whose pNull is above it comes back as null.
Validation rejects an option that a type doesn’t take, such as decimals on a text field.
Estimate and forecast options
An estimate needs evidence in the input text, such as comparable sales or past values. Its range can be too narrow on data unlike what the model has seen.
minandmaxbound the answer. They are numbers, or ISO dates for a date estimate.stepis the resolution: a positive number, a number of days for a date estimate, ormonthoryear.scale: "log"suits values that span orders of magnitude, such as prices.intervalis the forecast’s period:step,minute,hour,day,week,month,quarter, oryear.
The following fields ask for an estimate and a six-month forecast:
In values, an estimate is its point value, and a forecast is an array with one point value per period. A forecast extends the history in the text. It is not a time-series model, so check its ranges against outcomes before a Flow acts on them.
Configuration reference
The following table lists the fields of an extract step’s config:
The output object has the following fields:
Images
An extract step reads images together with the text. The model accepts PNG, JPEG, and WebP.
- Pass at most four images. Each can be 4 MiB decoded, and all images together 8 MiB.
- Pass each image as a data URL, or as a variable that holds a data URL or a
{ contentType, base64 }object. - The step refuses remote image URLs and asset IDs. To read an image from a URL, fetch it in an earlier step and pass the data.
Models, limits, and cost
GET /v1/extraction-models lists the supported extraction models, their limits, their pricing, and their credential requirements. The MCP tool list_extraction_models takes no arguments and returns the same list. Code Mode exposes it as runtype.listExtractionModels(). The catalog describes supported models. It doesn’t check whether your account can pay for a call.
The following table lists the facts for the default model:
Fields that don’t fit beside the text in one pass are split across parallel passes, and every pass reads the whole text. usage.passes reports how many ran. If the text is longer than the context, the step cuts it, sets truncated to true, and still succeeds with a warning on the step result.
Runtype bills a platform-funded extraction at the model’s listed rate plus the platform margin. If your account’s platform funding is blocked or exhausted, the step fails with a spend-limit error, and the step’s errorHandling applies. An organization that requires strict zero data retention can’t use this route, and its extract steps fail.
Clairic is a Cloudflare preview model. Cloudflare reports that it returns the same answers for the same input. Test it on your own documents before a Flow depends on it.
Design rules
Follow these rules to get reliable answers:
- Put the whole document in
state. Text answers are spans of that string. A summary from a prompt step loses the source and the spans. - Say what to compute. Add instructions such as “Item price plus tax” for a value that isn’t written down.
- Compute in code beyond one or two operations. A sum of two amounts or a day count is reliable. A total across many rows is not. Extract the rows as a list and add them in a Run Code step.
- Set
referenceDatewhen “today” matters. Relative dates and dates without a year are anchored on it. It defaults to the run’s start date. - Don’t ask the model to invent missing values. Branch on
nullinstead. - Give estimates evidence. Include comparable items or history in the text.
Errors and validation
Saving a Flow reports these codes for an extract step:
At run time, the step treats two kinds of failure differently:
- Input problems are an empty resolved text with no images, an image that is too large or not a data URL, an unknown model, or a malformed field map. With
errorHandlingunset, the step reports a failure and writes no output. Withcontinue, it writesdefaultValue. Withfail, it stops the Flow. - Model and funding failures follow
errorHandling. WitherrorHandlingunset, the step continues and writesdefaultValue, ornullwhen you set none.
A later step that reads claim.values fails when claim is null. Set errorHandling to { "onError": "fail" } on the extract step, or check for null before you read the output.
Self-hosted runtimes
A self-hosted @runtypelabs/runtime answers the step through its ExtractionProvider. The key mode picks the provider:
own: The runtime calls the Workers AIAIbinding of your deployment.platform: The runtime callsPOST /v1/runtime/extractionswith a Self-hosted Runtime key. Runtype funds and bills the call.hybrid: The runtime tries theAIbinding first. It calls Runtype only when no binding is configured.
For setup, see Self-hosting.
Next steps
Continue with one of these guides:
- Judgments: make a decision from the values you extracted.
- Using conditional steps: write the conditions that route on confidence.
- Using record steps: store
valuesas a Record. - Flow validation warnings: fix each validation code.