-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Bugfix/prompt security responses #17055
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
Open
davida-ps
wants to merge
11
commits into
BerriAI:main
Choose a base branch
from
davida-ps:bugfix/prompt-security-responses
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bugfix/prompt security responses #17055
davida-ps
wants to merge
11
commits into
BerriAI:main
from
davida-ps:bugfix/prompt-security-responses
+1,026
−736
Conversation
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
…rror handling, and streamline test cases for better maintainability and clarity.
|
@davida-ps is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
litellm/proxy/guardrails/guardrail_hooks/prompt_security/prompt_security.py
Outdated
Show resolved
Hide resolved
…/davida-ps/litellm into bugfix/prompt-security-responses
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.
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
✅ Test
Changes
pleas align this text
This pull request significantly improves the Prompt Security guardrail integration in
prompt_security.pyby introducing robust logging, clearer exception handling, more granular control over when guardrails are applied, and better support for complex response types. The changes also refactor how messages and outputs are sanitized, filtered, and updated after guardrail intervention. These improvements enhance reliability, observability, and maintainability of the guardrail logic.Key changes include:
1. Exception Handling and Logging Enhancements
PromptSecurityGuardrailAPIError,PromptSecurityBlockedMessage) for clearer error handling and more informative HTTP responses when content is blocked or API errors occur.2. Guardrail Hook Improvements and Control Flow
async_pre_call_hook,async_moderation_hook,async_post_call_success_hook, and streaming iterator hook) to ensure metadata is present, check if the guardrail should run for each event type, and consistently update applied guardrail headers. [1] [2] [3]3. Output and Message Handling for Advanced Response Types
ResponsesAPIResponse), including helper methods to normalize and update messages and instructions after guardrail intervention._scan_responses_api_outputto scan and potentially modify or block outputs in batch response APIs, ensuring consistent guardrail enforcement.4. Refactoring and Code Quality
5. Minor Cleanup