-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Feat: Content Filtering Exception Handling #3634
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
base: main
Are you sure you want to change the base?
Feat: Content Filtering Exception Handling #3634
Conversation
|
Is it possible to handle AWS Bedrock as well? Thanks. |
dsfaccini
left a comment
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.
Hey @AlanPonnachan thank you for the PR! I've requested a couple small changes, let me know if you have any questions
|
one more thing I missed, please include the name of the new exception in the fallback model docs
|
|
@dsfaccini Thank you for the review. I’ve made the requested changes. |
|
hey @AlanPonnachan thanks a lot for your work! It looks very good now, I requested a couple more changes but once that's done and coverage passes I think the PR will be ready for merge. |
|
@dsfaccini Thanks again for the review! I’ve applied the requested changes. Test coverage is now at 100%. |
Unified Content Filtering Exception Handling
This PR closes #1035
Standardizing how content filtering events are handled across different model providers.
Previously, triggering a content filter resulted in inconsistent behaviors: generic
ModelHTTPError(Azure),UnexpectedModelBehavior(Google), or silent failures depending on the provider. This PR introduces a dedicated exception hierarchy to allow users to catch and handle prompt refusals and response interruptions programmatically and consistently.Key Changes:
ContentFilterError(base),PromptContentFilterError(for input rejections, e.g., Azure 400), andResponseContentFilterError(for output refusals).PromptContentFilterErrorfor Azure's specific 400 error body andResponseContentFilterErrorwhenfinish_reason='content_filter'._process_responseto raiseResponseContentFilterErrorinstead ofUnexpectedModelBehaviorwhen safety thresholds are triggered.ResponseContentFilterError.tests/models/.Example Usage: