Skip to main content

vsl-langchain

A LangChain adapter for vsl-core: implements vsl_core.conformance.protocol.VSLAdapter and gates tool calls inside a create_agent() agent via AgentMiddleware.wrap_tool_call.

Is:

  • A VSLAdapter implementation (LangChainAdapter) that passes vsl_core.conformance.suite.run_conformance_suite with an empty result.
  • VSLToolMiddleware: a real langchain.agents.middleware.types.AgentMiddleware subclass that gates named tools, keyed by tool name, inside create_agent's middleware stack.

Is not:

  • A replacement for vsl-core itself — the PreNode/Invariant/Fallback/TerminalState constructs, the ledger, and the governance vocabulary all live in vsl-core. This package only compiles and wires those constructs into LangChain.
  • Compatible with the deprecated AgentExecutor/initialize_agent/create_react_agent APIs. Those predate the middleware system this adapter depends on — this package targets create_agent (LangChain >= 1.0) only.

Why wrap_tool_call, and why it's a real gate — not an assumption

AgentMiddleware.wrap_tool_call/awrap_tool_call is LangChain's own sanctioned interception point for tool execution. This was verified directly against the installed package's own docstring (langchain==1.3.17, not just documentation prose), which states outright:

"Middleware can call the handler multiple times for retry logic, skip calling it to short-circuit, or modify the request/response."

That is a genuine F1 pre-commitment guarantee: the middleware runs strictly before the tool executes, and structurally controls whether the real call (handler) ever happens at all. If a gate denies, handler is never called — the tool genuinely never runs, proven directly in this repo's own tests (test_integration.py asserts the handler's call log stays empty on denial, not just that a particular return value came back).

This supersedes an earlier, weaker finding (see project memory) that LangChain's callback system (on_tool_start, etc.) had unconfirmed blocking behavior — wrap_tool_call is a different, confirmed mechanism, not the same uncertain one.

Install

pip install vsl-langchain

This installs vsl-core (super-semantics-vsl, imported as vsl_core) and LangChain with it.

Quick taste

from langchain.agents import create_agent
from vsl_core.constructs import PreNode
from vsl_core.metrics import GammaEstimate
from vsl_langchain import LangChainAdapter, VSLToolMiddleware

adapter = LangChainAdapter()

async def monitor(candidate_input):
    amount = candidate_input["args"].get("amount", 0.0)
    return GammaEstimate(gamma_hat=2.0 if amount <= 1000.0 else 0.0)

pre_node = PreNode(
    name="refund-cap",
    description="Requires refund amount under the hard cap.",
    monitor=monitor,
)
gate = adapter.compile_pre_node(pre_node)

middleware = VSLToolMiddleware(gates_by_tool_name={"send_refund": gate})

agent = create_agent(
    model="anthropic:claude-sonnet-5",
    tools=[send_refund, lookup_order],  # lookup_order stays ungated -- no entry in gates_by_tool_name
    middleware=[middleware],
)

VSLToolMiddleware doesn't consume Fallback

A PreNode's Fallback (on_failure, delta_factor, max_retries, on_max_retries) is policy data only here — LangChainAdapter.compile_pre_node/compile_invariant never read pre_node.fallback. On denial, VSLToolMiddleware.awrap_tool_call returns an error ToolMessage once, immediately; there is no retry loop. This is the same inertness vsl-langgraph's LangGraphAdapter has — vsl-core's own PlainPythonReferenceAdapter doesn't consume Fallback either, so no adapter currently executes these fields as behavior.

VSLToolMiddleware doesn't write to the ledger either

Nothing in awrap_tool_call calls VerbaLedger.write* — a gate denial becomes an error ToolMessage, and that's it. If you want an audit trail of gate decisions, your own code (e.g. wrapping VSLToolMiddleware construction, or a separate middleware) has to call ledger.write_monitor/ledger.write(LedgerEntryType.PRE_NODE, ...)/write_verification explicitly, causally linked via caused_by — the same three entry types vsl-core's own building guide says to write around every gated call. Skip PRE_NODE and VerbaLedger.audit()'s drift_flagged_monitor_has_pre_node check fails on any denial — not a bug in audit(), just an incomplete write. An agent with no ledger calls anywhere produces real, working gating and zero audit trail — this package won't warn you, because from its point of view every gate did exactly what it was compiled to do.

To record the tool call itself, call ledger.write_action(identity_key=..., action_name=..., decision_id=...) inside the tool, with the same decision_id as the gate's write_gate_decision. ledger.enforcement(decision_id) then reads BEFORE_ACTION when every gate decision came before the tool ran (or a denial stopped it), and AFTER_ACTION when the tool ran first.

Where those writes are kept is up to you: VerbaLedger accepts any LedgerStore, and vsl-core includes InMemoryLedgerStore, JsonlLedgerStore (a local append-only file) and an optional immudb store.

What a gate reports

Gates take no assurance claim: build a PreNode or Invariant from its name, description and monitor or rule. Whether a gate ran before its tool is computed from the ledger, not declared (see vsl-core's "What a gate reports"). Code written for vsl-langchain 0.1 that still passes assurance_basis gets a FutureWarning from vsl-core; delete the argument.

Status

Alpha. Conformance-suite green. Integration-tested against the real ToolCallRequest/ToolMessage types from the actually-installed langchain/langgraph packages (not mocks) — covering: PreNode allow/deny, Invariant allow/deny, and an ungated tool passing straight through. Not yet tested against a full live create_agent() loop with a real or fake chat model — only the middleware's awrap_tool_call hook in isolation.

Layout

src/vsl_langchain/
└── adapter.py   LangChainAdapter (VSLAdapter conformance contract), VSLToolMiddleware (create_agent wiring)
tests/
├── test_conformance.py   run_conformance_suite(LangChainAdapter()) == []
└── test_integration.py   real ToolCallRequest/ToolMessage, PreNode + Invariant, allow/deny/ungated paths

Metadata

Release files for vsl-langchain 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vsl-langchain 0.2.0
File Size Uploaded Provenance Actions
vsl_langchain-0.2.0.tar.gz 9.1 kB With provenance Details for vsl_langchain-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vsl-langchain 0.2.0
File Interpreter ABI Platform Actions
vsl_langchain-0.2.0-py3-none-any.whl Python 3 none any Details for vsl_langchain-0.2.0-py3-none-any.whl

Total release size: 17.0 kB

Release files / vsl_langchain-0.2.0.tar.gz

Download URL vsl_langchain-0.2.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cdb84885153eee2a83485a4a985d6380be860e1feea7d2cf8a00069cd27f0254
BLAKE2b-256 checksum
How to use checksums
851cfdf6a0c62e43313f19258bd5d4025490003e550eddcc5c5816c6fc503c91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / vsl_langchain-0.2.0-py3-none-any.whl

Download URL vsl_langchain-0.2.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1f44db1e1bb326dd5f8ffbf79168cdf9d07d8c87edeb6de893e3bccabc9af65
BLAKE2b-256 checksum
How to use checksums
ae4b6d2dd4e1868636a3adf307c70cd7d5c39706d8bca0bcafaf1edfb1cf1d46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for vsl-langchain 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vsl_langchain-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page