You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/output.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -308,7 +308,7 @@ _(This example is complete, it can be run "as is")_
308
308
309
309
#### Native Output
310
310
311
-
Native Output mode uses a model's native "Structured Outputs" feature (aka "JSON Schema response format"), where the model is forced to only output text matching the provided JSON schema. Note that this is not supported by all models, and sometimes comes with restrictions. For example, Anthropic does not support this at all, and Gemini cannot use tools at the same time as structured output, and attempting to do so will result in an error.
311
+
Native Output mode uses a model's native "Structured Outputs" feature (aka "JSON Schema response format"), where the model is forced to only output text matching the provided JSON schema. Note that this is not supported by all models, and sometimes comes with restrictions. For example, Gemini cannot use tools at the same time as structured output, and attempting to do so will result in an error.
312
312
313
313
To use this mode, you can wrap the output type(s) in the [`NativeOutput`][pydantic_ai.output.NativeOutput] marker class that also lets you specify a `name` and `description` if the name and docstring of the type or function are not sufficient.
Copy file name to clipboardExpand all lines: pydantic_ai_slim/pydantic_ai/_json_schema.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,9 @@
15
15
classJsonSchemaTransformer(ABC):
16
16
"""Walks a JSON schema, applying transformations to it at each level.
17
17
18
+
The transformer is called during a model's prepare_request() step to build the JSON schema
19
+
before it is sent to the model provider.
20
+
18
21
Note: We may eventually want to rework tools to build the JSON schema from the type directly, using a subclass of
19
22
pydantic.json_schema.GenerateJsonSchema, rather than making use of this machinery.
20
23
"""
@@ -30,8 +33,15 @@ def __init__(
30
33
self.schema=schema
31
34
32
35
self.strict=strict
33
-
self.is_strict_compatible=True# Can be set to False by subclasses to set `strict` on `ToolDefinition` when set not set by user explicitly
36
+
"""The `strict` parameter forces the conversion of the original JSON schema (`self.schema`) of a `ToolDefinition` or `OutputObjectDefinition` to a format supported by the model provider.
37
+
38
+
The "strict mode" offered by model providers ensures that the model's output adheres closely to the defined schema. However, not all model providers offer it, and their support for various schema features may differ. For example, a model provider's required schema may not support certain validation constraints like `minLength` or `pattern`.
39
+
"""
40
+
self.is_strict_compatible=True
41
+
"""Whether the schema is compatible with strict mode.
34
42
43
+
This value is used to set `ToolDefinition.strict` or `OutputObjectDefinition.strict` when their values are `None`.
0 commit comments