Integration · Framework
Kyvvu for LangChain
One callback handler. Model calls, retrievers and tool calls are checked before they run, and every chain run becomes a task.
Set up
A few lines, then every step is checked.
- The handler owns the task
- It opens a task when the top-level chain starts and closes it when the chain ends or fails.
- Blocks stop the chain
- A blocked step raises KyvvuBlockedError and halts the chain. Warnings let the step run.
- Works offline
- Without an account, run it against the bundled baseline policies on your own machine.
from kyvvu import Kyvvufrom kyvvu_langchain import KyvvuLangChainHandlerkv = Kyvvu(api_url="https://platform.kyvvu.com", api_key="...", agent_key="bot")handler = KyvvuLangChainHandler(kv)# Pass handler through config={"callbacks": [handler]} when invoking a chain.What gets checked
Every callback becomes a step.
The built-in template turns LangChain callbacks into Kyvvu steps. The first matching rule wins, and you can replace the template with your own.
| Callback | Kyvvu step | Notes | |
|---|---|---|---|
| on_chain_start (top level) | task.start | Opens the task. The user's input is recorded as a step.message GET. | |
| on_chain_end (top level) | task.end | Closes the task. The answer is recorded as a step.message POST. | |
| on_chain_error (top level) | task.error | The chain raised an exception. | |
| on_llm_start, on_chat_model_start | step.model | The model id goes in properties.model. | |
| on_retriever_start | step.resource GET | Read-only retrieval. | |
| on_tool_start | step.resource GET or POST | GET for the tools in read_only_tools, POST for the rest. | |
| on_custom_event | step.unknown | Your own adispatch_custom_event. |
A tool is a step.resource whatever it does, so a policy on step.message doesn't see it. To treat send_* tools as messages, add a rule to the template, as in the example below.
When a policy says no
Stop an email to the wrong domain.
The docs' offline example: no account, no API key, no real model. A scripted model calls send_email for an address outside the approved domains, and the step is blocked before the tool runs.
- Before the tool runs
- The step is blocked before send_email's body runs, and KyvvuBlockedError reaches your invoke() call.
- Arguments as one string
- A tool's arguments arrive as one string in input, so the recipient rule matches input.input.
- Warnings let it run
- A high, medium or low policy records a warning and raises a Python UserWarning. Only critical blocks.
- id: send_tool description: Tools named send_* send a message match: event: "on_tool_start" name_pattern: "^send_" behavior: kind: "step.message" verb: "POST" step_name: "{{ name }}"Good to know
- Tools are recorded as resource steps: reads for the tools you list as read-only, writes for the rest.
- The handler opens and closes the task itself: don't call kv.start_task() around it, and don't also decorate a tool it runs.
- Under the bundled baseline every run warns on the final answer (agent_response): two EU AI Act Article 50 policies want a disclosure gate after the last model call. Record one, for example from an after_model middleware, and the warning goes.
- kyvvu template show langchain prints the mapping from LangChain events to Kyvvu steps, to copy and adjust.
- Tested with langchain 1.4, langgraph 1.2 and langchain-core 1.6.
Next
Try it before you install it.
In your browser
The playground
Build an agent's path, pick a policy and watch the engine decide.
On your machine
Five minutes, no account
kyvvu try runs a demo agent against the bundled baseline.