Repository navigation
Conversation
The launch-era recordings (invoice, types_present, types_absent, model_full_name, options_state_text) no longer match what Clairic returns: text and number answers are now generated, with valid, complete, decoder and raw metadata and no guess. They are re-recorded with identical requests; options_state_text drops its text null_threshold fields, which Clairic now rejects. New recordings cover the 0.3 answer model: boolean, enum, object and compute fields, source-only values and lists, object lists (including one read from a table), the new text, number and list options, a pattern no value matches, and the errors for forbidden option pairs. The 0.2 models parse every recording; only assertions on recorded values change (A-55120 now has no span because it appears twice, text and number answers carry no guess, usage and estimates moved). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic now answers fields in two ways. Date, time, datetime and duration fields are scored: Clairic ranks candidates and reports the best as guess, with p_null deciding against null_threshold. Text, number and list fields are generated: Clairic writes JSON, checks it against the field's options, and reports valid, complete, decoder, raw and tokens. Answer classes now follow the response shape: - TypedAnswer (p_null, confidence) is the base of DateAnswer, TimeAnswer, DatetimeAnswer and DurationAnswer, which keep guess. - GeneratedAnswer (valid, complete, p_null, confidence, plus the optional log_probability, failure_reason, retry_input_tokens, null_recovered and method labels) is the base of the generated answers. Single values add decoder, raw, tokens, span and their method labels. - TextAnswer and NumberAnswer become generated and lose guess; both list classes gain p_nulls and optional spans. Required keys are those present in every recorded answer of the family, invalid answers included (S0). A launch-era text answer no longer validates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0.1 split lists into TextListAnswer (with spans) and ListAnswer[V] (with per-item confidences) because the two had different response shapes. Clairic now returns one list shape for every item type: valid, complete, confidences, p_nulls, p_null and confidence, plus spans for text and number items. - TextListAnswer is removed; ListAnswer[str] replaces it. V is bound to str | int | float | date, so pyright keeps the exact item type. - A null list value, which the schema allows for invalid lists, reads as an empty list; valid and complete say why it is empty. - Pydantic does not check a generic's type argument, and pyright maps bool to int, so the compiler now rejects NumberAnswer[bool], ListAnswer[bool], ListAnswer[datetime] and other unsupported arguments before any request. - List(decimals=...) stays limited to number items. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic now accepts options per field type, and the specs expose exactly the documented ones a probe of every option on every type confirmed (December 2026): - Text: nullable, knowledge, enum, pattern, min_length, max_length. - Number: nullable, knowledge, enum, minimum, maximum, exclusive_minimum, exclusive_maximum, besides unit and decimals. - List: max_items, knowledge, enum, besides unit and decimals. Spec.to_payload sends the schema's camelCase keys (minLength, exclusiveMinimum, ...) and tuples as lists. The compiler rejects knowledge on lists that are not text or number lists, as it already did decimals on lists that are not number lists, and returns a deep copy now that payloads nest lists. Docstrings record what probes saw: nullable=False makes Clairic invent a missing value and still mark it valid, knowledge had no visible effect, and a pattern nothing matches yields null. A new test checks that every key the specs send exists in the vendored input schema, so the drift check and the specs fail together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic's new compute type derives a number from the input, such as a total or a difference. It is scored like dates and durations, not written, so ComputeAnswer[N] is a typed answer with value and guess. ComputeAnswer[int] sends integer: true. The Compute spec carries unit, decimals and null_threshold. It has no nullable option: Clairic requires compute answers to stay nullable. A Number spec on a compute field is refused at declaration. The docstring keeps the probe result: a simple invoice total came back wrong with a confidence of 0.45, so read confidence or compute in code when it matters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic's new boolean and enum types are generated answers, like text. - BooleanAnswer answers a yes or no question; its span is always None. - EnumAnswer[E] takes its allowed values from the annotation: EnumAnswer[Literal["card", "transfer", "cash"]] sends enum: ["card", "transfer", "cash"], and a value outside the Literal fails validation. E is bound to str, so pyright keeps the Literal. - The Boolean and Enum specs carry nullable only. The compiler rejects EnumAnswer[str], a union of Literals and an unparametrized EnumAnswer, and each "parametrize" error now shows an example for its own class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic's object type reads several related values together, and lists can now hold objects. Both take their properties from a plain Pydantic model: - ObjectAnswer[M] holds an instance of M, or None. - ListAnswer[M] holds a list of M; V's bound gains BaseModel, so pyright types res.data.lines.value as list[Line]. property_spans carries the per-row spans Clairic documents for tables. - Model fields map to properties: str to text, int to number with integer, float to number, bool to boolean, a Literal of strings to enum. "| None" is unwrapped, an alias names the property and a description becomes its instructions. Nested models, lists, dates and specs on properties are refused, matching the API (err_object_property_date). - Clairic returns null for properties the input lacks (objects recording); the docstring says to declare such fields "| None". - Lists of objects take only max_items, so unit and enum are refused. values_as now dumps nested values by alias, which fixes exporting objects whose properties use aliases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic's source_only option keeps only values printed in the input and
normalizes them from the printed text. It turns dates, times and
datetimes into generated answers, so it changes the answer's shape and
lives in the annotation:
- SourceOnlyAnswer[S], for int, float, date, time or datetime, sends the
matching type with source_only: true and takes the Number, Date, Time
or Datetime spec. Its answer adds printed_value and
normalization_method; when the printed text cannot be normalized
("1,200 EUR", "Friday") it is invalid, with value None and a
failure_reason.
- SourceOnlyListAnswer[L], for int, float or date, sends a source-only
list. Recordings show the plain list shape, so both list classes now
share a private base.
The compiler refuses knowledge (err_knowledge_source_only) and
null_threshold (err_source_only_null_threshold) on source-only fields,
and unsupported type arguments.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- README: the field table gains the new types and a generated/typed column, the answer table is split by family, a new example covers choices, objects, computed totals and printed values (outputs from a live call, December 2026), and an "Upgrading from 0.2" section lists the breaking changes. It also records what probes saw: nullable=False invents values, knowledge had no effect, compute can be wrong. - examples/invoice.py extracts an order with the new types and exports a list of objects with values_as. - The answers and specs module docstrings describe the two families and the validation policy: specs carry only the options each type accepts, and value ranges stay with Clairic while its API is in preview. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VianneyMI
marked this pull request as ready for review
December 5, 2026 13:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
clairic 0.3.0: typed and generated answers for the new Clairic schema
Stacked on #21 (0.2.0); retarget to
mainonce #21 is merged. Models everything Cloudflare's November 2026 schema offers. Design record:.cursor/brainstorms/clairic-schema-change.md(local).The model
Clairic answers in two ways, and the answer classes now follow the response shape:
GeneratedAnswer): Clairic writes JSON and checks it. CoversTextAnswer,NumberAnswer,BooleanAnswer,EnumAnswer[Literal[...]],ObjectAnswer[Model],ListAnswer[T],SourceOnlyAnswer[T]andSourceOnlyListAnswer[T]. Each answer carriesvalid,complete,raw,decoder,tokens,failure_reason, …TypedAnswer): Clairic scores candidates and keeps aguess. CoversDateAnswer,TimeAnswer,DatetimeAnswer,DurationAnswerand the newComputeAnswer.Literal, object properties from a plain model, andsource_onlyfromSourceOnlyAnswer. Specs carry only the options each type accepts.Commits
ListAnswer[V](TextListAnswerremoved), and check generic arguments at declaration.nullable,knowledge,enum,pattern, length and bound limits,max_items).values_asfor aliased nested models.Breaking changes (from 0.2)
TextListAnsweris removed: useListAnswer[str].guessis removed from text and number answers.Testing
examples/invoice.pyruns live.🤖 Generated with Claude Code