_AzureContentSafetyBaseMiddleware| Name | Type | Description |
|---|---|---|
endpoint | Optional[str] | Default: NoneAzure Content Safety resource endpoint URL. Falls back to
the |
credential | Optional[Any] | Default: NoneAzure credential. Accepts a
:class: |
project_endpoint | Optional[str] | Default: None |
exit_behavior | Literal['error', 'continue', 'replace'] | Default: 'error' |
violation_message | Optional[str] | Default: None |
apply_to_input | bool | Default: True |
apply_to_output | bool | Default: True |
name | str | Default: 'azure_protected_material' |
context_extractor | Optional[Callable[[AgentState[Any], Runtime[Any]], Optional[TextModerationInput]]] | Default: None |
| Name | Type |
|---|---|
| endpoint | Optional[str] |
| credential | Optional[Any] |
| project_endpoint | Optional[str] |
| type | Literal['code', 'text'] |
| exit_behavior | Literal['error', 'continue', 'replace'] |
| violation_message | Optional[str] |
| apply_to_input | bool |
| apply_to_output | bool |
| name | str |
| context_extractor | Optional[Callable[[AgentState[Any], Runtime[Any]], Optional[TextModerationInput]]] |
AgentMiddleware that detects protected material using Azure AI Content Safety.
Protected material detection checks whether text contains copyright-protected content such as song lyrics, news articles, book passages, or other protected intellectual property. Use this middleware to prevent agents from reproducing or accepting copyrighted content.
When protected material is detected, the middleware takes one of two actions:
"error" – raises :exc:ContentSafetyViolationError, halting the graph."continue" – replaces the offending message with a violation notice
(either a service-derived description or a custom violation_message)
and lets execution proceed.Both synchronous (before_agent / after_agent) and asynchronous
(abefore_agent / aafter_agent) hooks are implemented.
Azure AI Foundry project endpoint URL (e.g.
https://<resource>.services.ai.azure.com/api/projects/<project>).
Falls back to the AZURE_AI_PROJECT_ENDPOINT environment variable.
Mutually exclusive with endpoint.
What to do when protected material is detected. One of
"error" (default) or "continue".
Custom text used to replace the offending message
when exit_behavior="continue". Defaults to a message built
from the service response.
Whether to screen the agent's input (last
HumanMessage). Defaults to True.
Whether to screen the agent's output (last
AIMessage). Defaults to True.
Node-name prefix used when wiring this middleware into a
LangGraph. Defaults to "azure_protected_material".
Optional callable with signature
(state, runtime) -> Optional[TextModerationInput]
that receives the current graph state and the LangGraph
:class:~langchain.agents.middleware.Runtime execution context,
and returns the text to screen, or None to skip evaluation
entirely. When None (default) the middleware uses its
built-in extraction logic.