From 362f1bcca534bc450e7ad832aa60bd2d6d3b07f3 Mon Sep 17 00:00:00 2001 From: AkhileshNegi Date: Thu, 15 Oct 2026 23:15:14 +0530 Subject: [PATCH] fix(topic_relevance_llm): default on_fail to rephrase Topic relevance has no meaningful fix_value; the base default of `fix` returned an empty string on failure. Rephrase is the intended behaviour and what every caller already passes explicitly. Co-Authored-By: Claude Fable 5.1 --- .../config/topic_relevance_llm_safety_validator_config.py | 1 + backend/app/tests/validators/test_topic_relevance_llm.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/backend/app/core/validators/config/topic_relevance_llm_safety_validator_config.py b/backend/app/core/validators/config/topic_relevance_llm_safety_validator_config.py index c4e61d3..12ea833 100644 --- a/backend/app/core/validators/config/topic_relevance_llm_safety_validator_config.py +++ b/backend/app/core/validators/config/topic_relevance_llm_safety_validator_config.py @@ -11,6 +11,7 @@ class TopicRelevanceLLMSafetyValidatorConfig(BaseValidatorConfig): type: Literal["topic_relevance_llm"] + on_fail: GuardrailOnFail = GuardrailOnFail.Rephrase configuration: Optional[str] = None llm_callable: str = settings.DEFAULT_LLM_CALLABLE threshold: int = Field(default=settings.TOPIC_RELEVANCE_LLM_THRESHOLD, ge=1, le=3) diff --git a/backend/app/tests/validators/test_topic_relevance_llm.py b/backend/app/tests/validators/test_topic_relevance_llm.py index d819816..149f8cb 100644 --- a/backend/app/tests/validators/test_topic_relevance_llm.py +++ b/backend/app/tests/validators/test_topic_relevance_llm.py @@ -4,6 +4,7 @@ from guardrails.validators import FailResult, PassResult from app.core.constants import REPHRASE_ON_FAIL_PREFIX +from app.core.enum import GuardrailOnFail from app.core.validators.config.topic_relevance_llm_safety_validator_config import ( TopicRelevanceLLMSafetyValidatorConfig, ) @@ -403,6 +404,7 @@ def test_invalid_prompt_schema_version_returns_fail(): def test_config_defaults_to_forbidden_topics_schema(): config = TopicRelevanceLLMSafetyValidatorConfig(type="topic_relevance_llm") assert config.prompt_schema_version == 2 + assert config.on_fail == GuardrailOnFail.Rephrase def test_config_rephrase_without_fallback_uses_generic_text():