code_puppy icon indicating copy to clipboard operation
code_puppy copied to clipboard

`read_file` Tool Call Triggers `ValidationError` and UnexpectedModelBehavior

Open diegonix opened this issue 2 months ago • 2 comments

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_file vs edit_file).
  • Incorrect argument mapping or JSON serialization inside _call_tool().
  • Improper reuse of a validator for a different tool schema.

Suggested Fix

  1. Ensure that read_file and edit_file tools are validated with separate schemas.

  2. Confirm that the correct validator is being selected inside:

    pydantic_ai/_tool_manager.py::_call_tool
    
  3. Add more robust error handling before retrying — e.g., skip retries for deterministic validation errors (like extra fields).

  4. Consider logging the offending payload for debugging (when safe).

diegonix avatar Nov 06 '25 17:11 diegonix

@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.

mpfaffenberger avatar Nov 09 '25 12:11 mpfaffenberger

@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.

I think that was a hallucination, all the "invoke" agents were labeled "shell". I have to reproduce in newer versions.

diegonix avatar Nov 09 '25 16:11 diegonix