@@ -940,6 +940,7 @@ def tool(
940
940
docstring_format : DocstringFormat = 'auto' ,
941
941
require_parameter_descriptions : bool = False ,
942
942
schema_generator : type [GenerateJsonSchema ] = GenerateToolJsonSchema ,
943
+ strict : bool | None = None ,
943
944
) -> Callable [[ToolFuncContext [AgentDepsT , ToolParams ]], ToolFuncContext [AgentDepsT , ToolParams ]]: ...
944
945
945
946
def tool (
@@ -953,6 +954,7 @@ def tool(
953
954
docstring_format : DocstringFormat = 'auto' ,
954
955
require_parameter_descriptions : bool = False ,
955
956
schema_generator : type [GenerateJsonSchema ] = GenerateToolJsonSchema ,
957
+ strict : bool | None = None ,
956
958
) -> Any :
957
959
"""Decorator to register a tool function which takes [`RunContext`][pydantic_ai.tools.RunContext] as its first argument.
958
960
@@ -995,6 +997,8 @@ async def spam(ctx: RunContext[str], y: float) -> float:
995
997
Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
996
998
require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
997
999
schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
1000
+ strict: Whether to enforce JSON schema compliance (only affects OpenAI).
1001
+ See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
998
1002
"""
999
1003
if func is None :
1000
1004
@@ -1011,14 +1015,23 @@ def tool_decorator(
1011
1015
docstring_format ,
1012
1016
require_parameter_descriptions ,
1013
1017
schema_generator ,
1018
+ strict ,
1014
1019
)
1015
1020
return func_
1016
1021
1017
1022
return tool_decorator
1018
1023
else :
1019
1024
# noinspection PyTypeChecker
1020
1025
self ._register_function (
1021
- func , True , name , retries , prepare , docstring_format , require_parameter_descriptions , schema_generator
1026
+ func ,
1027
+ True ,
1028
+ name ,
1029
+ retries ,
1030
+ prepare ,
1031
+ docstring_format ,
1032
+ require_parameter_descriptions ,
1033
+ schema_generator ,
1034
+ strict ,
1022
1035
)
1023
1036
return func
1024
1037
@@ -1036,6 +1049,7 @@ def tool_plain(
1036
1049
docstring_format : DocstringFormat = 'auto' ,
1037
1050
require_parameter_descriptions : bool = False ,
1038
1051
schema_generator : type [GenerateJsonSchema ] = GenerateToolJsonSchema ,
1052
+ strict : bool | None = None ,
1039
1053
) -> Callable [[ToolFuncPlain [ToolParams ]], ToolFuncPlain [ToolParams ]]: ...
1040
1054
1041
1055
def tool_plain (
@@ -1049,6 +1063,7 @@ def tool_plain(
1049
1063
docstring_format : DocstringFormat = 'auto' ,
1050
1064
require_parameter_descriptions : bool = False ,
1051
1065
schema_generator : type [GenerateJsonSchema ] = GenerateToolJsonSchema ,
1066
+ strict : bool | None = None ,
1052
1067
) -> Any :
1053
1068
"""Decorator to register a tool function which DOES NOT take `RunContext` as an argument.
1054
1069
@@ -1091,6 +1106,8 @@ async def spam(ctx: RunContext[str]) -> float:
1091
1106
Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
1092
1107
require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
1093
1108
schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
1109
+ strict: Whether to enforce JSON schema compliance (only affects OpenAI).
1110
+ See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
1094
1111
"""
1095
1112
if func is None :
1096
1113
@@ -1105,13 +1122,22 @@ def tool_decorator(func_: ToolFuncPlain[ToolParams]) -> ToolFuncPlain[ToolParams
1105
1122
docstring_format ,
1106
1123
require_parameter_descriptions ,
1107
1124
schema_generator ,
1125
+ strict ,
1108
1126
)
1109
1127
return func_
1110
1128
1111
1129
return tool_decorator
1112
1130
else :
1113
1131
self ._register_function (
1114
- func , False , name , retries , prepare , docstring_format , require_parameter_descriptions , schema_generator
1132
+ func ,
1133
+ False ,
1134
+ name ,
1135
+ retries ,
1136
+ prepare ,
1137
+ docstring_format ,
1138
+ require_parameter_descriptions ,
1139
+ schema_generator ,
1140
+ strict ,
1115
1141
)
1116
1142
return func
1117
1143
@@ -1125,6 +1151,7 @@ def _register_function(
1125
1151
docstring_format : DocstringFormat ,
1126
1152
require_parameter_descriptions : bool ,
1127
1153
schema_generator : type [GenerateJsonSchema ],
1154
+ strict : bool | None ,
1128
1155
) -> None :
1129
1156
"""Private utility to register a function as a tool."""
1130
1157
retries_ = retries if retries is not None else self ._default_retries
@@ -1137,6 +1164,7 @@ def _register_function(
1137
1164
docstring_format = docstring_format ,
1138
1165
require_parameter_descriptions = require_parameter_descriptions ,
1139
1166
schema_generator = schema_generator ,
1167
+ strict = strict ,
1140
1168
)
1141
1169
self ._register_tool (tool )
1142
1170
0 commit comments