Skip to content

Commit 9cba90c

Browse files
committed
docs: clarify dict structured output schemas
1 parent 6a5db58 commit 9cba90c

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,11 @@ However you define your schema, don't duplicate it in your input prompt,
919919
including by giving examples of expected JSON output. If you do, the generated
920920
output might be lower in quality.
921921

922+
When defining schemas with Python type hints, `dict[str, AllowedType]`
923+
describes an object with arbitrary string keys whose values all share the same
924+
schema. To describe an object with a fixed set of named fields, use a Pydantic
925+
model or provide an explicit JSON Schema with `properties`.
926+
922927
#### JSON Schema support
923928

924929
Schemas can be provided as standard JSON schema.

codegen_instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ for message in chat.get_history():
383383
### Structured Outputs (Pydantic)
384384

385385
Enforce a specific JSON schema using standard Python type hints or Pydantic models.
386+
When using Python type hints, `dict[str, AllowedType]` describes an object with
387+
arbitrary string keys whose values all use the same schema. Use a Pydantic model
388+
or an explicit JSON Schema with `properties` for objects with a fixed set of
389+
named fields.
386390

387391
```python
388392
from google import genai

docs/_sources/index.rst.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,11 @@ However you define your schema, don't duplicate it in your input prompt,
952952
including by giving examples of expected JSON output. If you do, the generated
953953
output might be lower in quality.
954954

955+
When defining schemas with Python type hints, ``dict[str, AllowedType]``
956+
describes an object with arbitrary string keys whose values all share the same
957+
schema. To describe an object with a fixed set of named fields, use a Pydantic
958+
model or provide an explicit JSON Schema with ``properties``.
959+
955960
JSON Schema support
956961
^^^^^^^^^^^^^^^^^^^
957962

0 commit comments

Comments
 (0)