-
Notifications
You must be signed in to change notification settings - Fork 2
Fixed LLM Critic messages #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,12 @@ | |
| from sqlmodel import Session | ||
|
|
||
| from app.api.deps import AuthDep, SessionDep | ||
| from app.core.constants import BAN_LIST, REPHRASE_ON_FAIL_PREFIX | ||
| from app.core.constants import ( | ||
| BAN_LIST, | ||
| LLM_CRITIC_ERROR_MESSAGE, | ||
| LLM_CRITIC_REPHRASE_MESSAGE, | ||
| REPHRASE_ON_FAIL_PREFIX, | ||
| ) | ||
| from app.core.enum import ValidatorType | ||
| from app.core.guardrail_controller import build_guard, get_validator_config_models | ||
| from app.core.exception_handlers import _safe_error_message | ||
|
|
@@ -173,8 +178,9 @@ def _finalize( | |
| guard, request_log_id, validator_log_crud, payload, suppress_pass_logs | ||
| ) | ||
|
|
||
| rephrase_needed = validated_output is not None and validated_output.startswith( | ||
| REPHRASE_ON_FAIL_PREFIX | ||
| rephrase_needed = ( | ||
| validated_output is not None | ||
| and validated_output == LLM_CRITIC_REPHRASE_MESSAGE | ||
| ) | ||
|
|
||
| response_model = GuardrailResponse( | ||
|
|
@@ -244,7 +250,11 @@ def _extract_error_from_guard(guard: Guard, data: str) -> str | None: | |
| for log in logs: | ||
| log_result = log.validation_result | ||
| if isinstance(log_result, FailResult) and log_result.error_message: | ||
| if log.validator_name == ValidatorType.LLMCritic.name: | ||
| if log.validator_name in ( | ||
| ValidatorType.LLMCritic.name, | ||
| ValidatorType.LLMCritic.value, | ||
| "LLM_Critic", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have to repeat this here in three different ways
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a safeguard in case naming changes ever
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would the naming change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there has been inconsistency here in the error messages. In some of them, you see LLMCritic or LLM_Critic. Let's keep it as is. |
||
| ): | ||
| return _normalize_llm_critic_error(log_result.error_message) | ||
| return _redact_input(log_result.error_message, data) | ||
| return None | ||
|
|
@@ -307,12 +317,9 @@ def add_validator_logs( | |
|
|
||
|
|
||
| def _normalize_llm_critic_error(message: str) -> str: | ||
| if "failed the following metrics" in message: | ||
| return "The response did not meet the required quality criteria." | ||
| if "missing or has invalid evaluations" in message: | ||
| return ( | ||
| "The LLM critic could not evaluate one or more metrics. " | ||
| "The critic model returned an incomplete or malformed response. " | ||
| "Please retry." | ||
| ) | ||
| if ( | ||
| "failed the following metrics" | ||
| or "missing or has invalid evaluations" in message | ||
| ): | ||
|
rkritika1508 marked this conversation as resolved.
|
||
| return LLM_CRITIC_ERROR_MESSAGE | ||
| return message | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-guardrails
Length of output: 6315
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-guardrails
Length of output: 1948
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-guardrails
Length of output: 1400
Regression confirmed:
rephrase_neededsilently returns False for non-LLMCritic rephrase validators.Non-LLMCritic validators configured with
GuardrailOnFail.Rephrasecallrephrase_query_on_fail(), which returns a message prefixed withREPHRASE_ON_FAIL_PREFIX(e.g.,"Please rephrase the query without unsafe content. [reason]"). The current exact-equality check on line 181 only matchesLLM_CRITIC_REPHRASE_MESSAGE, so these validators will incorrectly setrephrase_needed=Falsedespite their output clearly signaling a rephrase requirement.The codebase has multiple tests for non-LLMCritic rephrase validators (profanity_free, llamaguard_7b, nsfw_text, uli_slur_match), confirming they are actively used. The unused import of
REPHRASE_ON_FAIL_PREFIXindicates this check was dropped unintentionally.Proposed fix
🤖 Prompt for AI Agents