Skip to content

Commit fa32fc3

Browse files
committed
Revert "rename partial_output to allow_partial"
This reverts commit 4dc4c72.
1 parent 5fc2bf9 commit fa32fc3

File tree

7 files changed

+19
-18
lines changed

7 files changed

+19
-18
lines changed

docs/durable_execution/temporal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ As workflows and activities run in separate processes, any values passed between
172172

173173
To account for these limitations, tool functions and the [event stream handler](#streaming) running inside activities receive a limited version of the agent's [`RunContext`][pydantic_ai.tools.RunContext], and it's your responsibility to make sure that the [dependencies](../dependencies.md) object provided to [`TemporalAgent.run()`][pydantic_ai.durable_exec.temporal.TemporalAgent.run] can be serialized using Pydantic.
174174

175-
Specifically, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `allow_partial` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
175+
Specifically, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `partial_output` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
176176
If you need one or more of these attributes to be available inside activities, you can create a [`TemporalRunContext`][pydantic_ai.durable_exec.temporal.TemporalRunContext] subclass with custom `serialize_run_context` and `deserialize_run_context` class methods and pass it to [`TemporalAgent`][pydantic_ai.durable_exec.temporal.TemporalAgent] as `run_context_type`.
177177

178178
### Streaming

docs/output.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,9 @@ print(result.output)
470470

471471
_(This example is complete, it can be run "as is")_
472472

473-
#### Partial validation {#partial-validation}
473+
#### Handling partial output in output validators {#partial-output}
474474

475-
You can use the `allow_partial` field on `RunContext` to implement your own partial validation in output validators.
476-
For example, you could choose to skip validation altogether if `allow_partial` is true:
475+
You can use the `partial_output` field on `RunContext` to handle validation differently for partial outputs during streaming (e.g. skip validation altogether).
477476

478477
```python {title="partial_validation_streaming.py" line_length="120"}
479478
from pydantic_ai import Agent, ModelRetry, RunContext
@@ -482,7 +481,7 @@ agent = Agent('openai:gpt-5')
482481

483482
@agent.output_validator
484483
def validate_output(ctx: RunContext, output: str) -> str:
485-
if ctx.allow_partial:
484+
if ctx.partial_output:
486485
return output
487486
else:
488487
if len(output) < 50:

pydantic_ai_slim/pydantic_ai/_run_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class RunContext(Generic[RunContextAgentDepsT]):
5858
"""The current step in the run."""
5959
tool_call_approved: bool = False
6060
"""Whether a tool call that required approval has now been approved."""
61-
allow_partial: bool = False
62-
"""Whether to allow partial validation of output."""
61+
partial_output: bool = False
62+
"""Whether the output passed to an output validator is partial."""
6363

6464
@property
6565
def last_attempt(self) -> bool:

pydantic_ai_slim/pydantic_ai/_tool_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def _call_tool(
147147
tool_call_id=call.tool_call_id,
148148
retry=self.ctx.retries.get(name, 0),
149149
max_retries=tool.max_retries,
150-
allow_partial=allow_partial,
150+
partial_output=allow_partial,
151151
)
152152

153153
pyd_allow_partial = 'trailing-strings' if allow_partial else 'off'

pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_run_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class TemporalRunContext(RunContext[AgentDepsT]):
1515
"""The [`RunContext`][pydantic_ai.tools.RunContext] subclass to use to serialize and deserialize the run context for use inside a Temporal activity.
1616
17-
By default, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `allow_partial` attributes will be available.
17+
By default, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `partial_output` attributes will be available.
1818
To make another attribute available, create a `TemporalRunContext` subclass with a custom `serialize_run_context` class method that returns a dictionary that includes the attribute and pass it to [`TemporalAgent`][pydantic_ai.durable_exec.temporal.TemporalAgent].
1919
"""
2020

@@ -49,7 +49,7 @@ def serialize_run_context(cls, ctx: RunContext[Any]) -> dict[str, Any]:
4949
'retry': ctx.retry,
5050
'max_retries': ctx.max_retries,
5151
'run_step': ctx.run_step,
52-
'allow_partial': ctx.allow_partial,
52+
'partial_output': ctx.partial_output,
5353
}
5454

5555
@classmethod

pydantic_ai_slim/pydantic_ai/result.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def stream_text(self, *, delta: bool = False, debounce_by: float | None =
117117
else:
118118
async for text in self._stream_response_text(delta=False, debounce_by=debounce_by):
119119
for validator in self._output_validators:
120-
text = await validator.validate(text, replace(self._run_ctx, allow_partial=True))
120+
text = await validator.validate(text, replace(self._run_ctx, partial_output=True))
121121
yield text
122122

123123
# TODO (v2): Drop in favor of `response` property
@@ -195,7 +195,9 @@ async def validate_response_output(
195195
text, self._run_ctx, allow_partial=allow_partial, wrap_validation_errors=False
196196
)
197197
for validator in self._output_validators:
198-
result_data = await validator.validate(result_data, replace(self._run_ctx, allow_partial=allow_partial))
198+
result_data = await validator.validate(
199+
result_data, replace(self._run_ctx, partial_output=allow_partial)
200+
)
199201
return result_data
200202
else:
201203
raise exceptions.UnexpectedModelBehavior( # pragma: no cover

tests/test_agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ def validate_output(ctx: RunContext[None], o: Foo) -> Foo:
339339

340340

341341
def test_output_validator_partial_sync():
342-
"""Test that output validators receive correct value for `allow_partial` in sync mode."""
342+
"""Test that output validators receive correct value for `partial_output` in sync mode."""
343343
call_log: list[tuple[str, bool]] = []
344344

345345
agent = Agent[None, str](TestModel(custom_output_text='test output'))
346346

347347
@agent.output_validator
348348
def validate_output(ctx: RunContext[None], output: str) -> str:
349-
call_log.append((output, ctx.allow_partial))
349+
call_log.append((output, ctx.partial_output))
350350
return output
351351

352352
result = agent.run_sync('Hello')
@@ -356,7 +356,7 @@ def validate_output(ctx: RunContext[None], output: str) -> str:
356356

357357

358358
async def test_output_validator_partial_stream_text():
359-
"""Test that output validators receive correct value for `allow_partial` when using stream_text()."""
359+
"""Test that output validators receive correct value for `partial_output` when using stream_text()."""
360360
call_log: list[tuple[str, bool]] = []
361361

362362
async def stream_text(messages: list[ModelMessage], info: AgentInfo) -> AsyncIterator[str]:
@@ -367,7 +367,7 @@ async def stream_text(messages: list[ModelMessage], info: AgentInfo) -> AsyncIte
367367

368368
@agent.output_validator
369369
def validate_output(ctx: RunContext[None], output: str) -> str:
370-
call_log.append((output, ctx.allow_partial))
370+
call_log.append((output, ctx.partial_output))
371371
return output
372372

373373
async with agent.run_stream('Hello') as result:
@@ -388,7 +388,7 @@ def validate_output(ctx: RunContext[None], output: str) -> str:
388388

389389

390390
async def test_output_validator_partial_stream_output():
391-
"""Test that output validators receive correct value for `allow_partial` when using stream_output()."""
391+
"""Test that output validators receive correct value for `partial_output` when using stream_output()."""
392392
call_log: list[tuple[Foo, bool]] = []
393393

394394
async def stream_model(messages: list[ModelMessage], info: AgentInfo) -> AsyncIterator[DeltaToolCalls]:
@@ -401,7 +401,7 @@ async def stream_model(messages: list[ModelMessage], info: AgentInfo) -> AsyncIt
401401

402402
@agent.output_validator
403403
def validate_output(ctx: RunContext[None], output: Foo) -> Foo:
404-
call_log.append((output, ctx.allow_partial))
404+
call_log.append((output, ctx.partial_output))
405405
return output
406406

407407
async with agent.run_stream('Hello') as result:

0 commit comments

Comments
 (0)