Guardrails let you run content safety checks before sending a prompt to an LLM (pre-check) and before returning the completion to your application (post-check). Each check is evaluated against the guardrail policies you configure in the LumiqTrace dashboard, and the SDK either allows the call to proceed, applies redaction, or throws aDocumentation Index
Fetch the complete documentation index at: https://docs.lumiqtrace.com/llms.txt
Use this file to discover all available pages before exploring further.
GuardrailBlockedError.
Enabling guardrails
Passguardrails: true to any wrapper function to enable both pre- and post-LLM checks with default settings.
guardrails: true is set, all calls through this client run a pre-check on the prompt and a post-check on the completion. If any guardrail blocks the content, a GuardrailBlockedError is thrown before the LLM call is made (pre) or before the result is returned (post).
Fine-grained configuration
Pass a configuration object instead oftrue to control exactly which phases run and how errors in the guardrail service are handled.
When
true, runs a content check on the prompt before the LLM call is made. A block at this phase prevents the LLM from ever receiving the prompt.When
true, runs a content check on the completion before it is returned to your application. A block at this phase prevents unsafe completions from reaching users.Controls behavior when the guardrail service itself returns an error (e.g. network timeout, service unavailable).
false(default): errors from the guardrail service are swallowed and the LLM call proceeds normally.true: errors from the guardrail service are re-thrown, blocking the LLM call. Use this in high-risk applications where you prefer to fail safe.
Handling GuardrailBlockedError
When a guardrail policy blocks content, the SDK throws a GuardrailBlockedError. Catch it to handle the block gracefully — for example, by returning a fallback response to the user.
GuardrailBlockedError properties
Which phase was blocked:
"pre" (input check) or "post" (output check).Array of results from individual guardrail policies that ran. Each result describes what the guardrail found and what action it took.
GuardrailResult fields
Each entry in error.results represents one guardrail policy evaluation:
Unique identifier of the guardrail policy that produced this result.
true if this guardrail allowed the content, false if it triggered.What the guardrail did. One of
"allowed", "blocked", "redacted", or "warned"."allowed"— content passed without modification"blocked"— content was rejected;GuardrailBlockedErroris thrown"redacted"— sensitive content was removed and the modified text is used instead"warned"— content was flagged but allowed through
Human-readable explanation of why this guardrail triggered, or
null if it did not trigger.The redacted version of the text, or
null if no modification was made. When a guardrail redacts content, the modified text is used in place of the original for the LLM call or returned response.Guardrails on other wrappers
Guardrails work on all provider wrappers. Pass the sameguardrails option to wrapAnthropic, wrapGoogle, wrapOpenRouter, or the LangChain callback handler.