Skip to content

Handle Azure AI content safety blocks - #1456

Merged
BenjaminMichaelis merged 3 commits into
mainfrom
benjaminmichaelis-content-safety-guardrails
Oct 5, 2026
Merged

BenjaminMichaelis merged 3 commits into
mainfrom
benjaminmichaelis-content-safety-guardrails

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Summary

  • Detect Azure Responses API content-filter failures and map them to a generic content_filtered response without returning provider details.
  • Return a consistent JSON/SSE moderation error and update the chat UI to display it while removing any partial assistant reply from a blocked stream.
  • Add focused tests for provider-error classification and message/stream endpoint contracts.

This is the application-side change for #1065. The paired Terraform change lowers the four harmful-content prompt thresholds for Violence, Hate, Sexual, and Selfharm from High to Low in IntelliTect-dev/EssentialCSharp.AzureResourceManagement.

Validation

  • dotnet test EssentialCSharp.Chat.Tests — 32 passed.
  • dotnet test EssentialCSharp.Web.Tests — 154 passed (serial run).
  • node --check EssentialCSharp.Web/wwwroot/js/chat-module.js — passed.

Azure policy enforcement for the deployed xAI/Grok model still requires environment verification.

Fixes: #1065

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Non-streaming incomplete content-filter responses can still return partial or empty output with HTTP 200.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds application handling for Azure AI content-safety blocks across chat services, API endpoints, streaming, and UI behavior.

Changes:

  • Classifies provider moderation failures using a domain exception.
  • Returns generic JSON/SSE moderation errors and removes blocked partial replies.
  • Adds endpoint contract tests and reusable test helpers.
File Description
EssentialCSharp.Chat.Shared/​Services/​AIChatService.cs Classifies Azure content-filter failures.
EssentialCSharp.Chat.Shared/​Services/​ChatBackendUnavailableException.cs Adds the moderation domain exception.
EssentialCSharp.Web/​Controllers/​ChatController.cs Maps moderation failures to JSON or SSE errors.
EssentialCSharp.Web/​wwwroot/​js/​chat-module.js Handles moderation events and fragmented SSE data.
EssentialCSharp.Web.Tests/​ChatModerationTests.cs Tests endpoint moderation contracts.
EssentialCSharp.Web.Tests/​McpTestHelper.cs Generalizes authentication helpers for derived factories.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread EssentialCSharp.Chat.Shared/Services/AIChatService.cs Outdated
Comment thread EssentialCSharp.Web.Tests/ChatModerationTests.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@BenjaminMichaelis
BenjaminMichaelis merged commit 2c36647 into main Oct 5, 2026
28 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the benjaminmichaelis-content-safety-guardrails branch October 5, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: No Content Safety Filtering or Output Guardrails on AI Responses

2 participants