How to extract fields from a document
Extract is schema-based key-value extraction. You define the fields you want and Sarvam Vision returns them as structured data. Use it for KYC, invoices, forms, and other structured data capture where you want specific fields, not the whole page.
Quick start
Extract takes the same document input, plus a schema describing the fields you want (or a saved config_id). The result is structured JSON with the field values you defined.
Full example (copy and run)
Submit, wait, and get the output in one script. Save it next to your document and run it.
For a one-page invoice and a schema with invoice_number, customer_name, and total_due, results.result is a flat object of your fields:
Parameters
Provide exactly one of schema or config_id. Sending both, or neither, returns a 400.
Common gotchas
schemais a JSON string, not an object. It is sent as a multipart form field. Usejson.dumps(schema)in Python andJSON.stringify(schema)in JavaScript. Passing a dict in Python raisesAttributeError: 'dict' object has no attribute 'read'.- The JavaScript SDK uses wire names, not camelCase. Parameters and response fields are
output_format,job_id, andpages_processed. filetakes an array in both SDKs.job_idis positional in JavaScript:getStatus(job_id), notgetStatus({ job_id }).
Schema rules
The inline schema is a JSON object with these constraints:
- Root must be
type: "object"with a non-emptypropertiesmap. - Every field needs a
typeand a non-emptydescription. The description guides the model, so make it specific. - Supported field types:
string,number,integer,boolean,object,array. - An optional
enummay be supplied to constrain values. - Maximum nesting depth is 4.
Write specific descriptions
Each field’s description guides the model. A specific description outperforms a generic one:
Reuse a schema
To reuse the same fields across many calls without re-sending the schema, save it as a Config and pass its config_id in place of schema.
- In the Doc Agents dashboard at indus.sarvam.ai, start an Extract project, upload a document, and describe the fields you want.
- When the project finishes, open the Config tab, adjust the schema, and click Save.
- Copy the
config_idshown on the saved Config (a UUID). Alternatively, click Deploy as API endpoint for a ready-made cURL command with theconfig_idfilled in.
Then send it with your document:
Output formats
Page limit: PDF and ZIP uploads are limited to 20 pages for Extract. Exceeding the limit returns a 400 Bad Request with code invalid_request_error. Split larger documents into batches before uploading.
Next steps
- Jobs & Errors: job states, polling, and error handling.
- How to classify: route documents to the right schema by type.