-
Notifications
You must be signed in to change notification settings - Fork 2
Updated endpoint and added "rephrase" on_fail action #20
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
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
* Validators: Added validator logs and organized code
4e65944 to
65a5c23
Compare
backend/app/models/validators/lexical_slur_safety_validator_config.py
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@backend/app/models/base_validator_config.py`:
- Around line 20-21: The resolve_on_fail method currently indexes _ON_FAIL_MAP
with self.on_fail causing a KeyError; change it to explicitly validate
self.on_fail against _ON_FAIL_MAP (e.g., if self.on_fail not in _ON_FAIL_MAP)
and raise a clear ValueError or custom exception that includes the invalid value
and the list of allowed keys, then return _ON_FAIL_MAP[self.on_fail] otherwise;
reference resolve_on_fail, _ON_FAIL_MAP and self.on_fail when making the change.
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@backend/app/api/routes/guardrails.py`:
- Around line 117-126: The returned safe_text currently includes the internal
REPHRASE_ON_FAIL_PREFIX marker; before constructing GuardrailResponse in this
block (variables validated_output, rephrase_needed, REPHRASE_ON_FAIL_PREFIX,
response_model), strip that prefix when rephrase_needed is true (e.g., remove
the prefix and any leading whitespace) so GuardrailResponse.safe_text contains
the clean prompt; then set rephrase_needed unchanged and pass the stripped value
into GuardrailResponse.
🧹 Nitpick comments (1)
backend/app/api/routes/guardrails.py (1)
46-68: Make/validators/success response shape consistent with failures.Failures return
APIResponse.failure_response(...), but success returns a raw dict. Consider wrapping success inAPIResponse.success_response(...)(and optionally adding aresponse_model) to keep the contract consistent.💡 Example adjustment
- return {"validators": validators} + return APIResponse.success_response(data={"validators": validators})
Summary
Target issue is #21.
Explain the motivation for making this change. What existing problem does the pull request solve?
This pull request does two things -
Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Notes
Please add here if any other information is required for the reviewer.
Summary by CodeRabbit
New Features
API Changes
Behavior & Config
Tests
✏️ Tip: You can customize this high-level summary in your review settings.