Skip to content

Commit a4f9c2c

Browse files
committed
revert changes to validator signature
1 parent 320d478 commit a4f9c2c

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

pydantic_ai_slim/pydantic_ai/_output.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,16 @@
5454
"""
5555

5656
OutputValidatorFunc = (
57-
Callable[[RunContext[AgentDepsT], OutputDataT_inv, bool], OutputDataT_inv]
58-
| Callable[[RunContext[AgentDepsT], OutputDataT_inv, bool], Awaitable[OutputDataT_inv]]
59-
| Callable[[RunContext[AgentDepsT], OutputDataT_inv], OutputDataT_inv]
57+
Callable[[RunContext[AgentDepsT], OutputDataT_inv], OutputDataT_inv]
6058
| Callable[[RunContext[AgentDepsT], OutputDataT_inv], Awaitable[OutputDataT_inv]]
6159
| Callable[[OutputDataT_inv], OutputDataT_inv]
6260
| Callable[[OutputDataT_inv], Awaitable[OutputDataT_inv]]
6361
)
6462
"""
65-
A function that always takes and returns the same type of data (which is the result type of an agent run). In addition:
63+
A function that always takes and returns the same type of data (which is the result type of an agent run), and:
6664
67-
* it can optionally take [`RunContext`][pydantic_ai.tools.RunContext] as a first argument
68-
* if it takes [`RunContext`][pydantic_ai.tools.RunContext] as a first argument, it can also optionally take `partial: bool` as a last argument
69-
* it can be async
65+
* may or may not take [`RunContext`][pydantic_ai.tools.RunContext] as a first argument
66+
* may or may not be async
7067
7168
Usage `OutputValidatorFunc[AgentDepsT, T]`.
7269
"""
@@ -165,29 +162,24 @@ async def execute_traced_output_function(
165162
class OutputValidator(Generic[AgentDepsT, OutputDataT_inv]):
166163
function: OutputValidatorFunc[AgentDepsT, OutputDataT_inv]
167164
_takes_ctx: bool = field(init=False)
168-
_takes_partial: bool = field(init=False)
169165
_is_async: bool = field(init=False)
170166

171167
def __post_init__(self):
172-
sig = inspect.signature(self.function)
173-
self._takes_ctx = len(sig.parameters) > 1
174-
self._takes_partial = len(sig.parameters) > 2
168+
self._takes_ctx = len(inspect.signature(self.function).parameters) > 1
175169
self._is_async = _utils.is_async_callable(self.function)
176170

177171
async def validate(
178172
self,
179173
result: T,
180174
run_context: RunContext[AgentDepsT],
181175
wrap_validation_errors: bool = True,
182-
partial: bool = False,
183176
) -> T:
184177
"""Validate a result but calling the function.
185178
186179
Args:
187180
result: The result data after Pydantic validation the message content.
188181
run_context: The current run context.
189182
wrap_validation_errors: If true, wrap the validation errors in a retry message.
190-
partial: Whether the output to validate is partial.
191183
192184
Returns:
193185
Result of either the validated result data (ok) or a retry message (Err).
@@ -197,9 +189,6 @@ async def validate(
197189
else:
198190
args = (result,)
199191

200-
if self._takes_partial:
201-
args = (*args, partial)
202-
203192
try:
204193
if self._is_async:
205194
function = cast(Callable[[Any], Awaitable[T]], self.function)
@@ -1079,7 +1068,7 @@ async def call_tool(
10791068
) -> Any:
10801069
output = await self.processors[name].call(tool_args, ctx, wrap_validation_errors=False)
10811070
for validator in self.output_validators:
1082-
output = await validator.validate(output, ctx, wrap_validation_errors=False, partial=ctx.tool_args_partial)
1071+
output = await validator.validate(output, ctx, wrap_validation_errors=False)
10831072
return output
10841073

10851074

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -951,16 +951,6 @@ def decorator(
951951
self._system_prompt_functions.append(_system_prompt.SystemPromptRunner[AgentDepsT](func, dynamic=dynamic))
952952
return func
953953

954-
@overload
955-
def output_validator(
956-
self, func: Callable[[RunContext[AgentDepsT], OutputDataT, bool], OutputDataT], /
957-
) -> Callable[[RunContext[AgentDepsT], OutputDataT, bool], OutputDataT]: ...
958-
959-
@overload
960-
def output_validator(
961-
self, func: Callable[[RunContext[AgentDepsT], OutputDataT, bool], Awaitable[OutputDataT]], /
962-
) -> Callable[[RunContext[AgentDepsT], OutputDataT, bool], Awaitable[OutputDataT]]: ...
963-
964954
@overload
965955
def output_validator(
966956
self, func: Callable[[RunContext[AgentDepsT], OutputDataT], OutputDataT], /

0 commit comments

Comments
 (0)