Skip to content

clairic 0.2.0: works with the November 2026 Clairic API - #21

Open
VianneyMI wants to merge 7 commits into
mainfrom
schema-drift/update
Open

VianneyMI wants to merge 7 commits into
mainfrom
schema-drift/update

Conversation

@VianneyMI

@VianneyMI VianneyMI commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

clairic 0.2.0: works with the November 2026 Clairic API

Between Nov 16 and Nov 23, Cloudflare changed Clairic's schemas without notice (found by the drift check, #20). 0.1.0 still passed its live tests but failed on common inputs. This PR updates the vendored schemas and makes everything 0.1 lets you declare work again. The new field types and answer metadata come in 0.3.

Commits

  • Update the vendored Clairic schemas (2026-11-24).
  • S1 Accept null spans in text lists. A list item that occurs more than once in the input now gets a null span. TextListAnswer.spans is list[Span | None].
  • S2 Drop the options Clairic now rejects.
    • Text loses unit and null_threshold, and Number loses null_threshold (each now a 422).
    • List(decimals=…) is refused on text and date lists before any request is sent.
  • S3 Rename the truncation warning to ClairicInvalidAnswerWarning. truncated: true now means some generated answers are invalid (Find what triggers truncated: true #15). The warning names them.
  • S4 Describe the current API in docstrings and README. Covers decode steps, generated tokens, the absent guess on text and number answers, and the 65,273-token limit.
  • S5 Switch the HTTP client to httpx2. Python 3.11 is now the minimum, and CI gains a lowest-dependencies job. Closes Switch the HTTP client from httpx to httpx2 #17.
  • Prepare the 0.2.0 release.

Breaking changes

  • ClairicTruncationWarning is renamed ClairicInvalidAnswerWarning.
  • Text(unit=…), Text(null_threshold=…) and Number(null_threshold=…) are removed (Clairic rejects them).
  • List(decimals=…) on text or date lists raises ModelDefinitionError.
  • TextListAnswer.spans items can be None.
  • timeout and http_client take httpx2 types. Python 3.10 is no longer supported.

Testing

  • ruff, pyright strict and pytest pass (113 tests). New recorded fixtures: list_repeated_items, truncated_invalid_answers, and err_text_* errors.
  • pytest -m live passes, including a new repeated-item test. examples/invoice.py runs live.
  • The suite also passes on Python 3.11 with the lowest allowed dependency versions.
  • scripts/check_schema_drift.py exits 0 against Cloudflare's current schemas.

🤖 Generated with Claude Code

@VianneyMI VianneyMI added the preview-api Depends on Clairic behavior that Cloudflare may change label Nov 24, 2026
@VianneyMI VianneyMI self-assigned this Dec 4, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VianneyMI
VianneyMI force-pushed the schema-drift/update branch from 161ee6b to c05af7a Compare December 5, 2026 08:57
@VianneyMI
VianneyMI changed the base branch from schema-drift-report to main December 5, 2026 08:57
VianneyMI and others added 6 commits December 5, 2026 09:59
Clairic now returns a null span for a list item that occurs more than
once in the input, since it cannot tell which occurrence it read. 0.1's
TextListAnswer required a Span for every item, so any text list with a
repeated name failed with "answers that do not fit".

TextListAnswer.spans becomes list[Span | None]. The new
list_repeated_items recording (Alice and Bob repeated, Carol once) drives
an answer test, a client test and the typing check; a live test covers
the same case against the API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic now rejects unknown options per field type with HTTP 422, and the
November schema narrowed several of them:

- unit no longer applies to text (err_text_unit),
- null_threshold applies to compute, date, time, datetime and duration
  only, so text and number reject it (err_text_null_threshold),
- decimals applies to number items only, so text and date lists reject
  it (err_text_list_decimals).

Text loses unit and null_threshold and keeps no option; the class stays so
declarations that attach Text() keep compiling. Number loses
null_threshold. The compiler refuses List(decimals=...) on text and date
lists before any request. ACCEPTED_KEYS now follows the published input
schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic's truncated flag changed meaning: it now reports that a generated
answer or list is invalid or incomplete, and the input is never truncated
(#15). ClairicTruncationWarning described the old meaning, so 0.2 renames
it without an alias.

The warning names the fields whose raw answer has valid: false or
complete: false ("Clairic returned 2 invalid answers: budget, due"), and
falls back to "Clairic reported truncated: true" when none is marked.
The warning tests replay truncated_invalid_answers, the first recorded
truncated: true response: two source-only fields read "1,200 EUR" and
"Friday", which Clairic could not normalize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docstrings and README still described the launch API: fields packed
into parallel 8,192-token passes, output_tokens always 0, a best-candidate
guess on every single value, and spans locating that guess.

Now:
- Usage: passes are sequential decode steps, input_tokens counts every
  prompt token including retries, output_tokens counts the tokens
  generated for text, number and list answers.
- Text and number answers are generated: guess stays None, confidence is
  the probability of the returned value, and a span is None when the
  value repeats or is not printed in the input.
- The size limit is 65,273 tokens per prompt (input plus fields).
- The README cost section quotes the December 2026 figures (1,823 input
  tokens over 9 decode steps for the invoice example), and the example
  no longer prints a guess.

The usage test now reads a current recording instead of asserting the
launch-era pass arithmetic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
httpx has had no stable release since 0.28.1 (December 2024); httpx2
(pydantic/httpx2) is its maintained successor with the same API under a
new import name, and python_jev already uses it (#17).

- The clients, tests and drift script import httpx2. The public
  `timeout` and `http_client` parameters now take httpx2 types.
- httpx2 requires Python 3.11, so requires-python, the classifiers, ruff,
  pyright and the CI matrix move to 3.11-3.14. Self and assert_type come
  from typing, and the typing-extensions dependency goes.
- A lowest-dependencies CI job, as in python_jev, runs the suite on 3.11
  with the lowest allowed versions of the direct dependencies.

Closes #17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VianneyMI VianneyMI changed the title Update the vendored Clairic schemas (2026-11-24) clairic 0.2.0: works with the November 2026 Clairic API Dec 5, 2026
@VianneyMI VianneyMI added this to the v0.2 milestone Dec 5, 2026
Comment thread .github/workflows/ci.yml
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping support for 3.10

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, deliberately. It comes with the httpx2 switch (S5, #17): httpx2 declares requires-python >=3.11 (2.18.0 on PyPI), so it can't be installed on 3.10. Python 3.10 also reached end of life in October 2026, and python-jev already targets 3.11–3.14.

Keeping 3.10 would mean staying on httpx 0.28.1, which has had no stable release since December 2024, or supporting both clients side by side. Neither seemed worth it before the 1.0 API freeze.

The PR description lists this under breaking changes, and the 0.2.0 release notes will say it too. CI now runs 3.11–3.14, plus a job on 3.11 with the lowest allowed dependency versions.

🤖 Claude Code

Comment thread examples/invoice.py
print(f"Invoice number: {number.value} (confidence {number.confidence:.4f})")
print(f"Due date: {data.due_date.value}")
print(f"Total: {data.total.value} USD")
print(f"PO number: {po.value} (p_null {po.p_null:.4f}, best guess {po.guess!r})")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing guess ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Cloudflare's November update, Clairic no longer returns a guess for text (or number) answers. They are now generated answers: Clairic writes the value, or null, and checks it, so there's no separate best candidate.

guess is only returned for typed answers (date, time, datetime, duration, compute). The new output schema says so: "guess: Typed answers only". The re-recorded invoice response confirms it: po_number comes back with value: null and no guess key.

In 0.2, TextAnswer.guess stays for compatibility but is always None. With the line kept, the example printed best guess None, which is misleading. 0.3 (#24) removes the attribute from text and number answers altogether.

🤖 Claude Code

Comment thread examples/invoice.py
print(f"PO number: {po.value} (p_null {po.p_null:.4f})")
print(f"Days to pay: {estimate.value} (80% interval {estimate.p10} to {estimate.p90})")
print(f"Input tokens: {result.usage.input_tokens} over {result.usage.passes} passes")
print(f"Input tokens: {result.usage.input_tokens} over {result.usage.passes} decode steps")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passes = decode steps ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's how the new output schema defines it: usage.passes, "Sequential decode steps."

At launch, passes counted the parallel 8,192-token passes fields were split into. Now Clairic decodes its generated answers step by step, and passes counts those steps. The invoice example takes 9 for 6 fields.

The SDK keeps the API's field name, usage.passes, and only the wording around it changes. Cloudflare's model page still describes passes the old way, so the schema is the only source for the new meaning.

If you prefer, the example could print {passes} passes (decode steps) to keep the API's word visible.

🤖 Claude Code

Comment thread src/clairic/answers.py
Comment on lines +9 to 15
Text, number and list answers are generated: Clairic writes the value, then checks it against the
field's options, so they carry no `guess`. Date, time, datetime and duration answers are scored
and keep a `guess`. Estimates and forecasts carry a distribution. Typed output constrains the
shape of an answer, not its correctness: use `confidence`, `p_null` and the percentile range to
decide which answers to act on and which to review.

Source: https://developers.cloudflare.com/workers-ai/concepts/extraction-models/

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 0.3 (#24) builds the class hierarchy on exactly this split. TypedAnswer (date, time, datetime, duration, compute: guess) and GeneratedAnswer (text, number, boolean, enum, object, lists, source-only: valid, complete, raw, failure_reason) become base classes, so the distinction this docstring describes is visible in the types.

🤖 Claude Code

Comment thread src/clairic/answers.py
The extracted text, or `None` when the input does not contain it.
guess: str | None
The best candidate text, reported even when `value` is `None`.
Always `None`: Clairic no longer returns a best candidate for text answers.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a line to say that this use to be valid with the initial Clairic API release but changed with Cloudflare updates

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Proposed wording for the guess attribute:

Always None: Clairic returned the best candidate text here, even when value was None, until Cloudflare's November 2026 update; it no longer returns one for text answers.

The same note fits NumberAnswer.guess, and the span line, which used to locate the guess. I'll apply it to all three once you give the go-ahead.

In 0.3 (#24) the attribute is gone, so there the history moves to the README's "Upgrading from 0.2" section.

🤖 Claude Code

Comment on lines +35 to +36
"value": null,
"valid": false,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the answer isn't found / isn't valid here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview-api Depends on Clairic behavior that Cloudflare may change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch the HTTP client from httpx to httpx2

1 participant