Skip to main content
By default, TokenPath chooses which phrases in the answer to attribute. Pass spans when your application needs to control that itself. For example, you may want to attribute one specific occurrence of a repeated number, or run a controlled experiment over fixed ranges. With spans, TokenPath attributes exactly the ranges you send and nothing else. The response has one entry per range, in the order you sent them.
Here [13, 26] covers $5.87 billion and [42, 45] covers 11%. The response keeps your order:
For a longer worked example, see the structured output notebook. It attributes every field of a JSON extraction and resolves two identical 15% values to the two different clauses they came from.

Rules

  • Each span is a half-open [start, end] range into answer, with 0 <= start < end <= len(answer).
  • Offsets use the request’s offset_encoding, and so does the len(answer) bound. See Offsets and encoding.
  • Send at least one span. "spans": [] and "spans": null fail with 422 validation_error. To let TokenPath choose, leave the field out.
  • A span whose phrase has no support comes back with "source": null.

Keep spans short

Attribution works best on fact-sized phrases, such as a number, a name, a date, an ID, or a short entity. Aim for 1 to 8 words. Numbers, dates, and names are usually best at 1 to 4. Good spans:
  • $5.87 billion
  • 11%
  • March 2, 2026
  • Jordan Lee
  • remaining performance obligations
  • 9,420 customers
Do not send full sentences, several facts joined by “and”, reasoning chains, paragraphs, or the whole answer as one span. A long span blends attention from several sources into one weak match.
The [[...]] marks only show the selected ranges. Strip them before you send the answer.

Selecting spans during generation

One way to get ranges is to ask the model to mark them as it writes:
Then strip the markers and record where each phrase landed in the clean answer:

Offset encoding

Explicit spans are read in the request’s offset_encoding, which defaults to utf-16. The helper above produces Python code-point offsets, so send "offset_encoding": "utf-32" with them. Offsets and encoding covers every language.