`read_file` Tool Call Triggers `ValidationError` and UnexpectedModelBehavior
read_file Tool Call Triggers ValidationError and UnexpectedModelBehavior
Version: code_puppy 0.252
Environment: Linux / Python 3.13
Description
When running a read_file tool call, the agent crashes due to a validation error inside the edit_file tool schema.
It appears that the tool manager attempts to process arguments incompatible with the expected schema, causing a pydantic_core.ValidationError followed by an UnexpectedModelBehavior after exceeding retry attempts.
Example Reproduction
READ FILE 📂 /[REDACTED]/README.md
Error invoking agent 'shell': Traceback (most recent call last):
File ".../pydantic_ai/_tool_manager.py", line 155, in _call_tool
args_dict = validator.validate_json(call.args or '{}', allow_partial=pyd_allow_partial)
pydantic_core._pydantic_core.ValidationError: 1 validation error for edit_file
file_path
Extra inputs are not permitted
For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden
Then:
pydantic_ai.exceptions.UnexpectedModelBehavior: Tool 'edit_file' exceeded max retries count of 3
Analysis
It seems that when the agent executes a read_file operation, it incorrectly routes or validates against the edit_file schema.
The file_path argument may be passed to a tool definition that does not expect it, resulting in an “extra inputs not permitted” validation failure.
After three failed retries, the UnexpectedModelBehavior is raised, stopping execution.
Possible causes:
- Misregistered or overlapping tool definitions (
read_filevsedit_file). - Incorrect argument mapping or JSON serialization inside
_call_tool(). - Improper reuse of a validator for a different tool schema.
Suggested Fix
-
Ensure that
read_fileandedit_filetools are validated with separate schemas. -
Confirm that the correct validator is being selected inside:
pydantic_ai/_tool_manager.py::_call_tool -
Add more robust error handling before retrying — e.g., skip retries for deterministic validation errors (like extra fields).
-
Consider logging the offending payload for debugging (when safe).
@diegonix - If Code Puppy was using the read_file validator, the entire agent wouldn't work. Can you provide steps to reproduce?
Error invoking agent 'shell': Traceback (most recent call last) - Do you have an agent named shell? It seems like the model hallucinated this one.
@diegonix - If Code Puppy was using the read_file validator, the entire agent wouldn't work. Can you provide steps to reproduce?
Error invoking agent 'shell': Traceback (most recent call last)- Do you have an agent namedshell? It seems like the model hallucinated this one.
I think that was a hallucination, all the "invoke" agents were labeled "shell". I have to reproduce in newer versions.