GuardrailRunnable. A runnable accepts a string or a dictionary with a query key, scans it, and returns a dictionary of the Guardrail result that the rest of the chain can branch on.
Install
LangChain support needs no extra, as described in Install Dome. Install Dome next to your LangChain packages:Create Runnable Objects
Build the Guards you want, following Configure Guardrails, then take the Guardrail objects from theDome instance:
flagged, guardrail_response_message for the original or sanitized content, and original_query.
Build a Guarded Chain
GuardrailRunnable is compatible with LangChain Expression Language, so you can compose it with prompts, models, and parsers:
ainvoke().
Branch on a Guardrail Decision
The chain above sends the blocked message to the model whenever the input Guardrail triggers. UseRunnableBranch to take a different path instead:
GuardrailRunnable also accepts a dictionary with prompt and response keys, which it converts into a structured payload for Detectors that need both sides of an exchange.Next Steps
Configure Guardrails
Define the Guards behind each runnable
Use Guardrails
Scan patterns outside LangChain