Skip to main content
extract is the fourth question type in Mercury Decide, alongside noul, choice, and score. It marks the parts of your text that match fields you describe in plain language, such as names, order numbers, or addresses. Every span is an exact substring of your input, with character offsets and a confidence score. Nothing is generated, so the model cannot return a value that isn’t in the text. Send extract questions to POST /v1/decisions with the model mercury-decide, either on their own or mixed with other question types in the same request. Requests without extract questions work exactly as before.

Send an extract request

Set INCEPTION_API_KEY to your API key. Describe each field you want in criteria, and use instructions for framing shared by all fields.

Read the response

Each extract answer has a spans map with one list per field, and a not_stated map. The request above returns:
  • start and end are character offsets into the source text, with end exclusive. text always equals source[start:end] in Python, or source.slice(start, end) in JavaScript.
  • A field can return several spans, or an empty list when nothing matches.
  • not_stated is the probability that the text contains nothing for that field.
  • A span’s confidence is the confidence of its least certain token.
  • Without criteria, the question has a single field named after the question. For example, a question named person is read at answers.person.spans.person.

Question fields

Plain-language constraints work in descriptions, for example “the first phone number mentioned” or “mark each person only once”.

Extract from an object state

When state is an object, every question still sees all of its fields, but an extract question needs source to say which string field to mark:
The span 12 Oak St, Austin TX comes back with start: 52 and end: 72, which are offsets into state.body.

Tips

  • Batch questions about the same text in one request. The text is encoded once and shared across questions, so one request with several questions costs far less than several requests.
  • Each token belongs to at most one field within a question. If two fields need the same words, such as city and address, only one of them gets the words. Put overlapping fields in separate extract questions.
  • Prefer more fields over more extract questions. Each extract question reads its own copy of the text, so it counts against the request’s token limit. Fields within one question share a single copy.
  • Extract the phrase, then parse it in code. For numbers and dates, extract the text that mentions them and convert it yourself.
  • Use a noul or choice for the verdict, and extract for the evidence. For example, ask whether a message is a complaint with a noul, and extract the sentences that show it.

Pricing and limits

Extract questions are billed like any Mercury Decide request: input tokens only, at the price on Models & Pricing. Output tokens are not charged.
  • An extract question can have up to 26 fields in criteria.
  • A request can be up to 32,768 tokens, including the internal copy of the text for each extract question. Split longer documents into sections, and add each section’s starting offset to its spans.
  • Requests that contain an extract question do not support images.
  • Validation errors, such as a missing source or too many fields, return a 422 error that names the problem. See Error Codes for other errors.