Extract Data from Documents
Extract Data from Documents
Use GroundX when you want a document to come back as JSON your application can
use. For example, a utility statement can return statement.account_number,
statement.total_amount_due, and service.service_address.
This guide uses the GroundX Python SDK to create the workflow, upload a document, and read the extracted JSON.
If you’d rather have an agent draft and iterate the YAML schema for you instead of writing it by hand, see Use GroundX With Your Agent; it walks through the same workflow with an agent doing the schema work.
Workflows are more general than extraction alone. The same mechanism can tune RAG output for a specific use case: inject custom prompts at any pipeline stage (document, section, or chunk), control chunk and section strategy, or route a step to a custom OpenAI-compatible LLM endpoint. This guide covers only the extraction-focused subset. The broader RAG-tuning capability isn’t yet documented as its own guide on this site.
What You’ll Do
- Write a YAML file that names the JSON keys you want back.
- Create a GroundX workflow from that YAML.
- Upload a document so GroundX can run the workflow.
- Call
get_extractto read the extracted JSON.
1. Describe The JSON You Want Back
Create a YAML file. Names such as statement and service become top-level
objects in the returned JSON. Under each one, fields: is the list of values
GroundX should extract.
This YAML tells GroundX to return JSON like this:
Keep this file focused on the JSON your application needs. Use names your
application will read, such as statement or service, not names that describe
how extraction runs.
2. Install The Extract Extra
Install the extract extra before using extraction workflow helpers.
Most applications can pass the YAML path directly to create or update. Load an extraction definition only when you need to inspect settings or reuse the same loaded definition across calls.
Custom workflow steps
For larger schemas, split extraction across named custom workflow steps. Each group uses
workflow_step to choose the step that extracts it, and each field uses
workflow_output_key to name the step output that maps back to the final JSON field.
Keep each custom step to 20 fields or fewer. The platform’s hard limit is 30, but
staying well under it improves extraction accuracy.
The returned JSON still uses the customer-facing YAML names, such as
invoice.invoice_number and line_items[].description.
For chunk- or section-level custom steps like line_item_labels above, get_extract
can currently return a 404 in some hosted environments, even though the workflow ran
correctly and was attached before ingest. This happens because structured output for
chunk/section-level steps can surface first in the document’s X-Ray output
(customChunkOutputs / customSectionOutputs), rather than in the document-level
extract artifact that get_extract reads. A 404 here doesn’t mean you did something
wrong; it’s known platform behavior for chunk/section-level custom steps, not a sign
the extraction failed.
3. Create And Assign The Workflow
Create the workflow from the YAML file. Then assign the workflow to the bucket where you will upload documents.
Use template for workflow-level prompt variables, such as {{LANGUAGE}} and
{{LANGUAGE_UNKNOWN}}, that should be available while the workflow runs.
Template values are strings.
Use client.workflows.add_to_account(...) instead when the workflow should be
the account default.
Update a workflow
Workflow updates send the full extraction settings, not a name-only patch. Pass the YAML path again, or pass a previously loaded definition when you intentionally want to reuse one.
Load from an existing workflow
Use this when you want to inspect or reuse the extraction definition that is already stored on a workflow.
See the SDK Method Reference at the end of this
page for the full parameter list of load_extraction_definition,
load_extraction_definition_from_yaml, load_extraction_definition_from_workflow,
create_extraction_workflow, and update_extraction_workflow.
4. Upload A Document
Upload documents to the bucket that has the workflow assigned to it. Use
process_level="full" so GroundX runs the workflow during ingest.
5. Get The JSON Back
After ingest completes, find the processed document and request its extracted JSON.
The result uses the same names from statement.yaml.
6. Improve The Results
The first pass is rarely perfect. Reaching high accuracy is an iteration loop: compare the extracted JSON against the values you expect, then fix the smallest part of the YAML that explains each miss. Change one value at a time so you can tell what each edit did.
For a single wrong or missing value:
- Edit that value’s
description,identifiers, orinstructions. Add the exact labels the document uses toidentifiers, and add a negative example toinstructionswhen the value is confused with a nearby one (for example, “Do not confuse the amount due with the previous balance”). - Ask for the value verbatim when formatting matters (“Return the amount exactly as printed, without a currency symbol”).
- If the value is missing entirely, confirm the document was read correctly
before tightening the prompt: inspect the document X-Ray. If the value is not
in the parsed content at all, no prompt change will recover it; if it is there
but not returned, broaden
identifiers.
For a repeating group (line items, charges, transactions):
- If rows are missing, instruct the group to capture every row, not just the first or the totals.
- If subtotals or a summary line are being captured as rows, exclude them explicitly (“Do not include subtotal, tax, or total lines”).
- If the same row appears twice, tell the group to return each row once.
- When several fields in the group are wrong, improve the group-level prompt rather than each field individually.
If the returned JSON uses the wrong names, update the YAML names before tuning prompts. Then prepare the YAML again, update the GroundX workflow, ingest another document, and read the result again. Repeat until the values match what you expect.
SDK Method Reference
These helpers require the extract extra: pip install "groundx[extract]".
client.load_extraction_definition(…)
Loads one source and returns an extraction definition you can inspect or reuse with create or update.
Existing workflow ID to read.
Path to a local YAML file. This is the normal application path.
YAML content as a string.
YAML content as a mapping. Use mapping_kind="workflow_extract" only when the
mapping is an existing workflow extract value.
A prepared extraction YAML object from the advanced SDK preparation API.
Use workflow_extract only when mapping is an existing workflow extract
value.
Request options for workflow-ID loading.
If workflow_id is set, the SDK loads from that workflow before considering
YAML or prepared inputs. Otherwise pass exactly one of path, yaml_text,
mapping, or prepared.
Returns an ExtractionDefinition with the workflow extract settings and any
workflow template, custom steps, output routes, and leaf fields from the selected
source.
client.load_extraction_definition_from_yaml(…)
Explicit YAML-only alias for client.load_extraction_definition(path=...),
yaml_text=..., mapping=..., or prepared=....
client.load_extraction_definition_from_workflow(…)
Explicit workflow-only alias for
client.load_extraction_definition(workflow_id=...).
The workflow ID to read.
Returns an ExtractionDefinition. If the stored workflow does not include the
original authored YAML metadata, the returned definition is still reusable for
create and update, but authored YAML inspection data is unavailable.
client.create_extraction_workflow(…)
Creates a workflow from an extraction definition or one YAML source.
A definition returned by load_extraction_definition(...) or one of its
explicit YAML/workflow aliases.
Path to a local YAML file. This is the normal create path.
YAML content as a string.
YAML content as a mapping. Use mapping_kind="workflow_extract" only for an
existing workflow extract value.
A prepared extraction YAML object from the advanced SDK preparation API.
Use workflow_extract only when mapping is an existing workflow extract
value.
Workflow name.
Request options forwarded to the workflow create call.
If definition is set, the SDK uses it before considering YAML or prepared
inputs. Otherwise pass exactly one of path, yaml_text, mapping, or
prepared.
Returns the normal workflow response. Assign the workflow to a bucket, group, or account after create.
client.update_extraction_workflow(…)
Updates an existing workflow from an extraction definition or one YAML source.
The workflow ID to update.
The full extraction definition to send.
Path to a local YAML file. This is the normal update path.
YAML content as a string.
YAML content as a mapping. Use mapping_kind="workflow_extract" only for an
existing workflow extract value.
A prepared extraction YAML object from the advanced SDK preparation API.
Use workflow_extract only when mapping is an existing workflow extract
value.
Optional workflow name to include with the full update.
Request options forwarded to the workflow update call.
If definition is set, the SDK uses it before considering YAML or prepared
inputs. Otherwise pass exactly one of path, yaml_text, mapping, or
prepared. Update sends the full extraction workflow settings, not a name-only
patch, so pass the YAML or definition again when custom settings should remain
in effect.
Returns the normal workflow response.

