GuardrailRunnable wrapper, which turns a Guardrail into a standard LangChain Runnable. No extra install is required beyond LangChain itself, since the integration builds on langchain-core.
Building a Guarded Chain
1
Create the Guardrail Runnables
First build a Dome instance and pull its input and output Guardrails with
get_guardrails(), then wrap each one.GuardrailRunnable accepts an optional enforce argument (default True). When enforce=False, the Guardrail flags content but does not replace it, which is useful for shadow-logging in production.2
Assemble the Chain
GuardrailRunnable objects are compatible with LCEL. A runnable returns a dict; downstream steps read guardrail_response_message (the sanitized text) and flagged (whether the Guardrail triggered).{"query": ...} dict.3
Add Branching (Optional)
By default the blocked message flows to the model whenever the input Guardrail triggers. To route around the model instead, use LangChain’s
RunnableBranch and key on the flagged field.Next Steps
LangGraph
Secure a LangGraph Agent with the Trust Runtime
Configure Guardrails
Choose which Guards run