mlflow/mlflow · warning · HTTPException (GuardrailViolation message)

{e}

Error message

{e}

What it means

In the /invocations route, after a chat request completes, a pre-LLM guardrail can raise GuardrailViolation. The handler converts it to HTTP 400 with the guardrail's own message as detail, so the payload text is just the guardrail violation reason (e.g. PII detected, banned content).

Source

Thrown at mlflow/server/gateway_api.py:771

                    request_dict,
                    response,
                    auth_headers=auth_headers,
                    usage_tracking=endpoint_config.usage_tracking,
                )

            try:
                return await maybe_traced_gateway_call(
                    _guarded_chat,
                    endpoint_config,
                    user_metadata,
                    request_headers=headers,
                    request_type=GatewayRequestType.UNIFIED_CHAT,
                    on_complete=make_budget_on_complete(
                        store, workspace, endpoint_config.endpoint_id
                    ),
                )(payload)
            except GuardrailViolation as e:
                raise HTTPException(status_code=400, detail=str(e))

    elif "input" in body:
        # Embeddings request
        endpoint_type = EndpointType.LLM_V1_EMBEDDINGS
        try:
            payload = embeddings.RequestPayload(**body)
        except Exception as e:
            raise HTTPException(status_code=400, detail=f"Invalid embeddings payload: {e!s}")

        provider, endpoint_config = _create_provider_from_endpoint_name(
            store, endpoint_name, endpoint_type
        )

        return await maybe_traced_gateway_call(
            provider.embeddings,
            endpoint_config,
            user_metadata,
            request_headers=headers,

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Read the detail text to see which guardrail fired and remove the offending content from the prompt.
  2. Redact or sanitize inputs client-side (e.g. strip emails/PII) before sending.
  3. If the guardrail is too strict, adjust the guardrail configuration on the endpoint (rules/regexes) or remove it.

Example fix

// before
{"messages":[{"role":"user","content":"email me at foo@bar.com"}]}

// after
{"messages":[{"role":"user","content":"email me at [REDACTED]"}]}
Defensive patterns

Strategy: try-catch

Validate before calling

# pre-check input against your own guardrail rules client-side
import re
if re.search(PII_PATTERN, user_text):
    user_text = redact(user_text)

Try / catch

try:
    resp = requests.post(url, json=body)
except requests.HTTPError as e:
    if e.response.status_code == 400:
        raise UserInputError(e.response.text) from e  # show guardrail reason to end user

Prevention

When it happens

Trigger: Invoking a chat endpoint whose config defines guardrails (e.g. pii/redaction or content filters) and the submitted message content trips a pre-LLM guardrail check.

Common situations: Users pasting credit card numbers/emails into a chat app with PII guardrails; prompts containing blocked keywords configured by the admin.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/f1f9b6a80811c9e0. Report an issue: GitHub.