Files
Max Isbey 053ffdac34 Derive the output validator on FuncMetadata construction; review fixes
FuncMetadata now derives its structured-output validator (and the schema, when
none is given) from `output_model` when it is constructed, keeping it in a
private attribute instead of a public cached property guarded by an assert. The
fields are still read live and the validator is rebuilt if `output_model` is
reassigned, so code that clears or sets `output_schema`/`output_model` on a
registered tool keeps working. `func_metadata()` simply constructs the metadata
inside the existing "not serializable" fallback.

Results are validated with `by_name=True` as well as by alias, so a TypedDict or
model that declares `Field(alias=...)` accepts the Python-side keys a tool
returns while structured content still carries the aliases the schema advertises.

The `typing.TypedDict` rebuild for Python < 3.12 now runs inside that validator
build, so `output_model` stays the declared class and rebuild failures take the
same fallback as pydantic's own; it also carries over `__module__`,
`__qualname__`, `__pydantic_config__` and `ReadOnly`, and an unresolvable key
annotation (`NameError`) degrades like it does on 3.12+.
2026-08-19 16:08:20 +00:00
..