Skip to main content

External Moderation

The external-moderation policy sends content to a third-party moderation provider. It blocks content that the provider flags. It also blocks when the provider cannot return a correct decision. The gateway supports eight providers:

  • openai-moderation
  • azure-content-safety
  • bedrock-apply-guardrail
  • embedding-endpoint
  • presidio
  • guardrails-ai
  • dynamo-ai
  • lakera

The policy runs in the input phase by default. Attach it to a response stage with conditional chain metadata when necessary.

Configuration

pack:
name: external-moderation-example
version: 1.0.0
enabled: true

policies:
chain:
- external-moderation

policy:
external-moderation:
provider: openai-moderation
secret_key_ref:
env: VERDICTAN_OPENAI_API_KEY
categories:
- violence
- self-harm
threshold: 0.5
timeout_ms: 3000
fail_closed: true

Fields

PropertyTypeDefaultDescription
providerenumruntime fallback: openai-moderationSet one of the eight provider values explicitly. The active lint schema has a different default.
secret_key_refobjectSecret reference in object form, typically secret_key_ref.env.
endpointstringProvider endpoint URL when the provider uses one.
categoriesstring[][]Optional provider-specific category filters.
thresholdnumber0.5Score threshold used by the provider adapter.
timeout_msinteger3000Provider timeout in milliseconds.
fail_closedbooleanruntime behavior: trueSet true explicitly. Provider and configuration failures block even when this legacy field is false.
aws_regionstringBedrock region.
aws_access_key_envstringOptional Bedrock access-key env var name.
aws_secret_key_envstringOptional Bedrock secret-key env var name.
aws_session_token_envstringOptional Bedrock session-token env var name.
guardrail_idstringBedrock guardrail identifier.
guardrail_versionstringBedrock guardrail version.
embedding_modelstringModel name for provider: embedding-endpoint.
reference_textsstring[][]Reference texts for provider: embedding-endpoint.
presidio_languagestringen at runtime when not specifiedOptional language hint for provider: presidio.
presidio_entitiesstring[][]Optional Presidio entity filter list.
guard_namestringName for provider: guardrails-ai.
policy_idstringPolicy identifier for provider: dynamo-ai.
lakera_categoriesstring[][]Optional Lakera category filters.

Provider notes

ProviderWhat you must supply
openai-moderationSupply secret_key_ref.env. endpoint is optional.
azure-content-safetysecret_key_ref.env and endpoint
bedrock-apply-guardrailaws_region, guardrail_id, guardrail_version, and credentials if your runtime does not have them
embedding-endpointSupply endpoint and reference_texts. You can also supply embedding_model and secret_key_ref.
presidioSupply endpoint. presidio_language is optional because the adapter uses en by default.
guardrails-aiendpoint and guard_name
dynamo-aiendpoint and policy_id
lakeraSupply secret_key_ref.env. endpoint is optional.

How it works

  1. The gateway makes one string from the input message content.
  2. It dispatches the content to the selected provider adapter.
  3. The adapter normalizes the provider response into flagged, scores, and reason.
  4. If flagged is true, the policy blocks with reason_code: external-moderation.flagged.
  5. A missing credential, timeout, network error, invalid status, or malformed response blocks with policy.external_moderation_unavailable.

Best practices

  • Use secret_key_ref.env. Do not use inline secrets in YAML.
  • Start with one provider. Add providers only when they are necessary.
  • Set fail_closed: true explicitly and test provider reliability before rollout.
  • Do not configure webhook. The active moderation runtime has no webhook provider.
  • Scope categories only when the provider adapter supports the category names you want.

Next steps