feat(provider): add provider-specific policy refusal markers - #630
Closed
bukeeastrey wants to merge 1 commit into
Closed
feat(provider): add provider-specific policy refusal markers#630bukeeastrey wants to merge 1 commit into
bukeeastrey wants to merge 1 commit into
Conversation
Add common content filter and safety markers to _is_policy_refusal() including 'content_filter', 'content filter', 'responsible_ai_policy', 'content management policy', 'flagged by content filter', and 'blocked by safety'. This ensures content moderation and safety policy refusals from Azure OpenAI, OpenAI, Gemini, and Anthropic are classified as POLICY_REFUSAL instead of falling through to BAD_REQUEST or UNKNOWN.
Contributor
|
Closing as superseded. Reviewed alongside #779 on issue #629; #779 was picked. Same markers, same place — the difference is the test coverage. #779 adds negative cases pinning that the widened list does not capture This PR currently also conflicts with Thanks for the contribution. |
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
When upstream LLM providers (such as Azure OpenAI, OpenAI, Gemini, or Anthropic) filter or reject a prompt or response due to content safety or moderation policies, they return specific error codes or message phrases (e.g.
content_filter,responsible_ai_policy,content management policy,flagged by content filter,blocked by safety).Previously,
_is_policy_refusal()only matched a small set of generic phrases, causing these upstream safety blocks to fall through and be misclassified asBAD_REQUESTorUNKNOWN.This PR adds common provider safety and moderation markers to
_is_policy_refusal()to ensure all such errors consistently classify asProviderFailureKind.POLICY_REFUSAL.Changes
src/agentos/provider/failures.py: Added the following markers to_is_policy_refusal():"content_filter"(Azure OpenAI / OpenAI error code & finish reason)"content filter"(e.g."The prompt was flagged by content filter")"responsible_ai_policy"(Azure / cloud policy violation code)"content management policy"(Azure OpenAI canonical error phrasing)"flagged by content filter""blocked by safety"(Google Gemini block reason)tests/test_provider_failure_classification.py: Added unit tests covering policy refusal error shapes across Azure OpenAI, OpenAI, Gemini, and Anthropic.Verification
uv run ruff check src/agentos/provider/failures.py tests/test_provider_failure_classification.py(Passed)uv run mypy src/agentos/provider/failures.py --show-error-codes(Passed)uv run pytest tests/test_provider_failure_classification.py -q(93/93 tests passed)closes #629