Fix TypeError: unhashable type in ToolCorrectnessMetric for unhashable tool outputs (#2815)#2822
Open
HarperZ9 wants to merge 1 commit into
Open
Fix TypeError: unhashable type in ToolCorrectnessMetric for unhashable tool outputs (#2815)#2822HarperZ9 wants to merge 1 commit into
HarperZ9 wants to merge 1 commit into
Conversation
…nfident-ai#2815) ToolCorrectnessMetric places ToolCall instances into a set during component-level evaluation. ToolCall.__hash__ routes input_parameters and output through _make_hashable, whose final branch returned arbitrary objects unchanged, assuming they were primitive hashable types. When the output (or a value nested in input_parameters) is an unhashable object, such as a LangChain ToolMessage or a pydantic model that defines __eq__ without __hash__, hashing raised `TypeError: unhashable type`, breaking evals_iterator() on agent traces. Fall back to a stable repr() for any value that is not hashable. Primitives and already-hashable objects are returned unchanged. Adds a regression test covering an unhashable object both as the output and nested in input_parameters. Closes confident-ai#2815 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
A quick note on the red checks, so the CI status is not misleading:
Happy to rebase or adjust if you handle the black drift separately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2815.
ToolCorrectnessMetricraisesTypeError: unhashable typeduring component-level evaluation (evals_iterator()) when a tool call'soutput, or a value nested in itsinput_parameters, is an arbitrary unhashable object, e.g. a LangChainToolMessageor a pydantic model that defines__eq__without__hash__.Root cause
ToolCorrectnessMetric._calculate_non_exact_match_scoreputsToolCallinstances into aset, which callsToolCall.__hash__. That routesinput_parametersandoutputthrough_make_hashable(deepeval/test_case/llm_test_case.py). Its final branch returned any non-collection object unchanged, assuming it was a primitive hashable type:When
objis unhashable,hash((self.name, input_params_hashable, output_hashable))then raisesTypeError.Fix
Fall back to a stable
repr()for any value that is not hashable. Primitives and already-hashable objects are returned unchanged, so existing behavior is preserved; only the previously-crashing path changes.Reproduction (before the fix)
Both return an
intafter the fix and the tool calls can be placed in aset.Tests
Adds
test_tool_call_hashing_with_unhashable_typesintests/test_core/test_test_case/test_single_turn.py, covering an unhashable object both asoutputand nested ininput_parameters. No API key required.black --checkand the existing hashing tests are clean.Disclosure: authored with AI assistance (Claude), reviewed and verified before submitting.