LangChain chat models accept an OpenAI-compatible base_url. Point that URL at ValGuard so every chain, tool-calling step, and agent loop shares the same rule packs and audit rows.
When you need this
A LangChain router picks the wrong tool because the model returned plausible JSON with an invalid enum. ValGuard blocks or re-asks on the completion before bind_tools sees the payload.
Setup
- Create a ValGuard agent per role (router, extractor, writer).
- Attach schema and policy packs; start in shadow mode.
- Configure
ChatOpenAI(or equivalent) withbase_url=https://api.valguard.ai/v1, your ValGuard API key, anddefault_headers={"X-VG-Agent": "<slug>"}. - Enforce when shadow metrics look stable.
Code
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="openai/gpt-4o-mini",
base_url="https://api.valguard.ai/v1",
api_key=os.environ["VG_API_KEY"],
default_headers={"X-VG-Agent": "langchain-router"},
)
resp = llm.invoke("Classify: duplicate charge on invoice 4412")
Honest limits
- ValGuard validates LLM completions on the path you route. It does not validate arbitrary Python tool code unless that tool calls back through ValGuard.
- Block and re-ask rules buffer streaming completions. See Trust.
- For graph state machines with explicit nodes, also see LangGraph.
Related
Next step
Wire shadow mode with the quickstart, then read LLM output validation.