GuardrailRunnable. A runnable accepts a string or a dictionary with a query key, scans it, and returns the Guardrail result as a dictionary so downstream components can branch on it.
Install
Install Dome with the dependencies required by the local Detector and OpenAI model used in this example:- The
langchain-openaipackage installslangchain-core, which is required byGuardrailRunnable. It also provides theChatOpenAIintegration used below. - The
localDome extra installs the model dependencies for theprompt-injection-deberta-v3-baseDetector configured in this example (LangChain does not use this extra).
If you use remote inference or Detectors included in the base package, you can install
vijil-dome without the local extra. See Install Dome for all available extras.Create Runnable Objects
Build the Guards you want by following Configure Guardrails, then retrieve 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