-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Feature requestNew feature requestNew feature request
Description
Problem
When tool calls fail validation, Pydantic AI sends "2 validation errors: ... Fix the errors and try again" to the LLM. Some models interpret this as user input rather than an internal error, causing confused responses.
Proposed
Add a way to customize/override the validation error message format. For example with a callable.
Even better if we'd be able to inject RunContext into that formatter so we could do conditionals based on what the state of the conversation is.
class Agent:
def __init__(
self,
...,`
tool_retry_formatter: Callable[[str, RunContext], str] | None = None`
):
...
# Usage
def format_tool_error(error_message: str, ctx: RunContext) -> str:
return f"Customizable text that tells the agent exactly what to do, that couldn't be explained pre-validation failure\n{error_message}"Use Case
Prepending custom error
Benefits
- Clearer error context for LLMs (being able to inform that THIS IS NOT THE USER)
- Custom agent behavior on validation failures
References
Metadata
Metadata
Assignees
Labels
Feature requestNew feature requestNew feature request