Repository navigation
feat(topic_relevance_llm): skip validator when its LLM is unreachable - #200
Conversation
content_safety, topic_relevance_llm, pii_remover and gender_assumption_bias now share a SkipOnError mixin: any exception inside the validator (expired OpenAI key, model load error, unparseable LLM output) returns a new SKIPPED outcome, passes the text through unchanged, and lets the rest of the chain run. Previously topic_relevance_llm turned an LLM error into a FailResult, so with on_fail=rephrase every message got the fallback reply. Adds SKIPPED to the validatoroutcome Postgres enum (migration 012). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one): 1
Please check the settings in the CodeRabbit UI or the
|
Drop the SkipOnError mixin. Only topic_relevance_llm's completion() call now maps to SKIPPED; unparseable LLM replies still FAIL so users can't prompt-inject the scorer into skipping. content_safety, pii_remover and gender_assumption_bias run locally and are back to main; their failure handling moves to a separate PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.
Still open from earlier reviews (2):
- Unresolved: 1 minor or pre-existing, 1 blocking on lines changed since (possibly already fixed).
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
The catch-all except let callers trigger a skip with their own input (oversized message -> ContextWindowExceededError, content-filter trip, lone surrogate). Now only auth, connection/timeout, provider 5xx and a plain BadRequestError (OpenAI's revoked-key response) skip; input-caused BadRequestError subclasses, rate limits and unexpected errors still fail. Response extraction moved into the parse try so a malformed reply fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code review found no new issues
No new issues were found in this update; 2 findings from earlier reviews are still open above.
Still open from earlier reviews (2):
- Unresolved: 1 minor or pre-existing, 1 blocking on lines changed since (possibly already fixed).
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
| EMPTY_MESSAGE_ERROR = "Empty message." | ||
| TOPIC_OUT_OF_SCOPE_ERROR = "Input is outside the allowed topic scope." | ||
| # PassResult metadata key the route maps to outcome SKIPPED. | ||
| SKIPPED_METADATA_KEY = "skipped" |
There was a problem hiding this comment.
This key needn't be put into a global variable. Can use the string directly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What Changed
topic_relevance_llm: when the LLM can't be reached, outcome isSKIPPEDinstead ofFAIL. Text passes through unchanged, rest of the chain runs.AuthenticationError,PermissionDeniedError,APIConnectionError,Timeout,ServiceUnavailableError,InternalServerError, and a plainBadRequestError(what OpenAI returns for a revoked / wrong-project key; matched withtype(e) is, notisinstance).FAIL, so nobody can trigger a skip on purpose:ContextWindowExceededError,ContentPolicyViolationError(and otherBadRequestErrorsubclasses), encoding errors, and anything unexpected.RateLimitErroralso fails, so one tenant flooding the shared key can't switch the check off for everyone. Theerrorholds only the exception type ("LLM call failed: ContextWindowExceededError"), not the provider message.content=None) still returnsFAIL, as onmain.ValidatorOutcome:PASS | FAIL→PASS | FAIL | SKIPPED; migration012adds the value to thevalidatoroutcomePostgres enumvalidator_results[].erroron a skip ="Validator skipped: LLM call failed (<ExceptionType>)"; exception text (truncated to 500 chars) stored only invalidator_log.meta.result_metadata.skip_detailsuppress_pass_logsstill writesSKIPPEDrows (onlyPASSis suppressed)Summary
Why validators failed closed: in #71 (Mar 2026), the first
topic_relevance, built on LLMCritic, wrapped any error inFailResult("LLM critic returned an invalid response: ..."). That's the common guardrails convention: if a validator can't check a message, it fails it rather than letting it through.guard.validate(text) topic_relevance_llm._validate completion() raises - return FailResult("LLM call failed: …") # any error → fallback reply to every user + if not (isinstance(e, _SKIP_ERRORS) or type(e) is litellm.BadRequestError): + return FailResult("LLM call failed: <Type>") # input-caused / 429 / unexpected + return PassResult(metadata={"skipped": "Validator skipped: LLM call failed (<Type>)"}) next validator # still runs _summarize_validator_results / add_validator_logs - outcome = result.outcome.upper() # PASS / FAIL + outcome, error = _outcome_and_error(result) # PASS / FAIL / SKIPPEDEvidence
completionraising →FailResult,error="LLM call failed: litellm.AuthenticationError: … Incorrect API key provided: sk-proj-****1234 …"; withon_fail=rephraseand no fallback that string reached the end user insafe_text.After:
test_erroring_validator_is_skipped_and_chain_continues— realGuardwithTopicRelevanceLLM(completion raising) +LexicalSlur:topic_relevance_llm skipped: LLM call failed with BadRequestError→{'skipped': 'Validator skipped: LLM call failed (BadRequestError)', 'skip_detail': 'litellm.BadRequestError: OpenAIException - You do not have access to the project tied to the API key.'}Exceptionfail; a reply with empty choices fails.376 passed, 14 skipped(excludingtest_topic_relevance_llm_live.py, which needs a working OpenAI key).Merge Danger
Door: one-way
ALTER TYPE validatoroutcome ADD VALUE 'SKIPPED'can't be dropped;downgrade()is a no-op. Rolling back the code afterSKIPPEDrows exist leaves the oldValidatorOutcomeunable to load them, so anything readingvalidator_logbreaks.Blast Radius: fail-open,
topic_relevance_llmonlyERRORlog linetopic_relevance_llm skipped: LLM call failed with <Type>per message andSKIPPEDrows invalidator_log.GuardrailTrace.tsxusesisFlagged = outcome !== 'PASS', soSKIPPEDrenders as "Flagged" until a third "Skipped" badge is added. kaapi-backendsummarize_validator_resultspassesoutcomethrough as a string, no change needed.OPENAI_API_KEYunset at build time, missing prompt template) still fail as before.🤖 Generated with Claude Code