Repository navigation
feat(validator): topic_relevance_llm forbidden-topics default and localized fallback reply - #166
Merged
Merged
Conversation
- Default prompt_schema_version to 2 (configuration = forbidden topics) - Add fallback_message, translated into the user's language in the same LLM call and returned as safe_text with rephrase_needed=true - Fix stored-config prompt_schema_version not applied to topic_relevance_llm Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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 ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- rephrase_needed: any failing validator with on_fail=rephrase - localized_fallback joins _OPTIONAL_FIELDS; max_tokens doubles with fallback - drop redundant tests Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nners Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the duplicated 4-field JSON schema and repeated must-include line; live check with gpt-4o-mini gives the same results as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prajna1999
approved these changes
Oct 14, 2026
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
Target issue is ProjectTech4DevAI/kaapi-backend#1251
Glific Guardrails v1 exposes
topic_relevance_llmas "Scope control": the NGO enters disallowed topics and a custom reply, and the reply should reach the user in their own language. Today the validator defaults to allowed-topics mode, has no custom reply, and silently ignores the prompt version of stored configs.prompt_schema_version→ 2, soconfigurationmeans forbidden topics (PRD choice). Validator not used in production yet, so no caller breaks.fallback_message: withon_fail=rephrase, returned assafe_textinstead of "Please rephrase the query without unsafe content…".rephrase_neededistruewhenever a validator withon_fail=rephrasefails.prompts/topic_relevance_llm/fallback_translation.md): the model returns a 5th JSON fieldlocalized_fallback. If it is missing or invalid, the originalfallback_messageis used.topic_relevance_config_idnow carries the storedprompt_schema_versionfortopic_relevance_llmtoo (it was only copied fortopic_relevance, so forbidden-topic configs ran as allowed-topic).Sample request with inline validator:
{ "request_id": "6f1c2a9e-3b7d-4e2a-9c1f-8d5b0a7e4c21", "input": "क्या आप बता सकते हैं कि मेरे पेट में लड़का है या लड़की?", "validators": [ { "type": "topic_relevance_llm", "stage": "input", "on_fail": "rephrase", "configuration": "Forbidden topics:\n- Sex determination of a fetus: any question about finding out or predicting whether an unborn baby is a boy or a girl\n- Politics: elections, political parties, politicians", "fallback_message": "Sorry, I can only help with maternal health and nutrition questions." } ] }Expected:
safe_textis the Hindi translation offallback_message,rephrase_needed: true. v2 judges against the full topic description, so a sentence per topic works better than a bare name.Optional fields:
prompt_schema_version2thresholdsettings.TOPIC_RELEVANCE_LLM_THRESHOLDllm_callablesettings.DEFAULT_LLM_CALLABLE"gpt-4o-mini"topic_relevance_config_idconfigurationon_failmust be"rephrase"forfallback_messageto be used (the default"fix"returns an empty string).fallback_messagecannot be"".Checklist
max_tokens,rephrase_neededfor translated fallback.Notes
Live check with gpt-4o-mini (forbidden: fetus sex determination, politics):
Known limitations / follow-ups:
fallback_messageis set (adds ~30–60 output tokens). Asking for it only on fail made gpt-4o-mini returnnull.on_fail=fixreturns an empty string for this validator (documented).🤖 Generated with Claude Code