Skip to content

Conversation

open-swe[bot]
Copy link
Contributor

@open-swe open-swe bot commented Jul 17, 2025

Fixes #47

Problem

When an LLM returns invalid tool calls (e.g., due to token limits or parsing errors), the system would raise an AttributeError: 'ExtractionState' object has no attribute 'tool_call_id' during validation and retry attempts.

Solution

This PR implements two key fixes:

  1. In _ExtendedValidationNode._func(), added logic to:

    • Check for invalid tool calls in additional_kwargs
    • Create appropriate error ToolMessages for invalid tool calls
    • Ensure graceful handling when tool_calls is empty
  2. In validate_or_repatch(), updated routing logic to:

    • Only route to 'patch' when state contains tool_call_id
    • Prevent AttributeError by routing to 'end' for states without tool_call_id

Changes

  • Modified trustcall/_base.py to handle edge cases in tool call processing
  • Added comprehensive test case in tests/unit_tests/test_extraction.py to validate the fix
  • Ensured code passes linting and formatting checks

Test Coverage

  • Added async test test_invalid_tool_call_handling() that simulates LLM responses with empty tool_calls and invalid tool call information

Impact

  • Prevents AttributeError during extraction and validation
  • Gracefully handles scenarios with malformed tool calls
  • Improves robustness of the extraction system

@open-swe open-swe bot added the open-swe label Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to add validation to the pydantic model throws Error
0 participants