Repository navigation
fix: report model refusals instead of KeyError in LLM classifiers - #281
Open
Leandro (Leandr0Duar7e) wants to merge 1 commit into
Open
Leandro (Leandr0Duar7e) wants to merge 1 commit into
Leandro (Leandr0Duar7e) wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Part of #280
Summary
Model refused to respond (finish_reason=content_filter)when a classifier response hasfinish_reason: "content_filter", instead of failing later withKeyError: 'choice'(Python) orUnknown score choice undefined(JS).OpenAILLMClassifier._postprocess_response) and JS (OpenAIClassifier).finish_reason: "content_filter"andselect_choicecalled with{}.Root cause
OpenAI-compatible APIs report a refused or filtered response with
finish_reason: "content_filter". Claude Haiku 5.5 refusals arrive this way through the Braintrust gateway, with emptyselect_choicearguments. The classifiers readargs["choice"]without checking the finish reason, so the refusal surfaced as an unrelatedKeyError.This PR only makes the failure clear. The prompt wording that triggers the refusal is discussed in #280 and will come in a separate PR.
Validation
main,test_llm_classifier_raises_on_refusalfails withKeyError: 'choice'and the JS test fails withUnknown score choice undefined. Both pass with this change.uv run --extra dev --extra scipy pytest py/autoevals/test_llm.py -k raises_on_refusal: 1 passedpnpm exec vitest run js/llm.test.ts -t "raises on refusal": 1 passedmain; all of them needOPENAI_API_KEYor thelitellmextra.pre-commit runon the changed files (black, ruff, codespell) andprettier@3.3.2 --checkpnpm run build🤖 Generated with Claude Code