Fix/gsm8k tuple response attribute error#1628
Conversation
|
@SYED-M-HUSSAIN is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
|
hey @SYED-M-HUSSAIN have you tested the code out? THe if else looks really complicated, not sure if everything is necessary? |
|
Hey @penguine-ip , yes I’ve tested the code, it’s working as expected. I agree the if-else logic looks a bit dense, but it’s designed to handle various response formats from different model types. That said, I’m open to simplifying it if we can keep the flexibility intact. Let me know your thoughts! |
|
@SYED-M-HUSSAIN yes please lets simplify it a bit! we can always fix it further if someone raises an issue again :) |
|
Thanks @penguine-ip, I’ve refactored the method to simplify the if-else chain |
|
@SYED-M-HUSSAIN thanks! |
Fix: Handle tuple responses in GSM8K model output to avoid AttributeError
📍 Summary
This PR resolves (https://github.com/confident-ai/deepeval/issues/1612) by adding robust handling for non-standard model responses (e.g., tuples) that previously caused an
AttributeErrorin theGSM8Kbenchmark.🐞 Problem
The original implementation assumed that model outputs would always return an object with an
.answerattribute (e.g.,NumberSchema). However, in some cases, the model returns a tuple, causing the following error:This occurred specifically at:
and earlier:
✅ Solution
This PR includes a targeted fix that preserves backward compatibility:
Replaced unsafe
.values()unpacking with direct dictionary key access for safer and clearer code.Introduced a helper method
_extract_prediction_from_response()to robustly extract the prediction from various formats:NumberSchemaobjects.textor.contentattributesImproved exception handling by catching both
AttributeErrorandTypeErrorin case of unexpected structures.🧼 Code Changes
In
gsm8k.py:Replaced:
With:
Modified:
To:
Added a new method
_extract_prediction_from_response()for robust prediction extraction.🛡️ Impact
AttributeError: 'tuple' object has no attribute 'answer'#1612)🧾 Related
AttributeError: 'tuple' object has no attribute 'answer'#1612