[open-swe] fix: Handle invalid tool calls and prevent AttributeError in extraction #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
In
_ExtendedValidationNode._func()
, added logic to:additional_kwargs
ToolMessages
for invalid tool callstool_calls
is emptyIn
validate_or_repatch()
, updated routing logic to:tool_call_id
tool_call_id
Changes
trustcall/_base.py
to handle edge cases in tool call processingtests/unit_tests/test_extraction.py
to validate the fixTest Coverage
test_invalid_tool_call_handling()
that simulates LLM responses with emptytool_calls
and invalid tool call informationImpact