Skip to content

Commit 560dc38

Browse files
author
Sainikhil Juluri
committed
docs(structured-output): document NotRequired key omission
AGENTS.md requires user-visible behaviour changes to update docs in the same PR. The TypedDict section claimed structured_content was "identical to the BaseModel version", which is no longer true for keys the tool omits.
1 parent 3eeae46 commit 560dc38

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

docs/servers/structured-output.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ Not every shape deserves a class. A `TypedDict` produces the same schema:
102102

103103
A `TypedDict` is a plain `dict` at runtime, so that is what you build and return. The schema, the validation, and `structured_content` are identical to the `BaseModel` version (minus the descriptions, which `TypedDict` has no place for).
104104

105+
A key marked `NotRequired` (or any key at all under `total=False`) follows `TypedDict` semantics: if your tool leaves it out of the returned dict, it is **absent** from `structured_content` rather than present as `null`. That matches the published `outputSchema`, which declares those properties with their own type and simply omits them from `required`.
106+
107+
!!! note
108+
Below Python 3.12, import `TypedDict` from `typing_extensions` rather than `typing` whenever you use `NotRequired` — pydantic needs the `typing_extensions` variant to see the qualifier.
109+
105110
## A dataclass
106111

107112
Dataclasses work too, and so does any ordinary class whose attributes have type hints. The SDK builds a Pydantic model out of the annotations behind the scenes.

0 commit comments

Comments
 (0)