Blog
Skarn's guard in an agent you build
The skarn-guard Python package checks each tool call of an agent you build before the tool
runs. The adapter for your runtime hands the call to the skarn binary on the same server and gets
back allow, ask or deny. The binary scans the call with the detection engine that skarn check
uses, writes each flagged call to its guard log, and makes no network call. Adapters ship for LangChain,
the OpenAI Agents SDK, Strands, Google ADK, an MCP server, the Amazon Bedrock AgentCore Gateway and the
LiteLLM proxy.
Published 2026-12-04. Measured on macOS with Skarn 0.39.0, skarn-guard 0.39.0, LangChain 1.4.10 and Python 3.12.
Install
The first command installs the skarn binary; the install page covers the other
platforms. The langchain extra pins the LangChain version the adapter was tested against, and
the package page lists the extra for each runtime.
One tool call, checked
The script below is a LangChain agent with one tool, write_file. A scripted model stands in
for yours, so it runs with no API key and no model call: its one turn asks to write an AWS secret key into
config.py. The key is made up for this post. The only Skarn line is the middleware.
Save it as agent.py and run it:
The tool ran. SkarnGuard() starts in audit mode, which records the verdict and blocks
nothing. The record is in the guard log:
The guard would have denied the write. The key is never printed: the preview keeps its first character
and its last two. skarn guard report needs no license. It reads the package's default log,
~/.cache/skarn/guard-sdk-audit.jsonl, and counts flagged calls only, because a call the guard
allows is not logged.
The same call, enforced
Change the middleware to SkarnGuard(mode="enforce") on a machine with a Skarn license of
a paid tier installed. Remove the config.py the audit run wrote, then run the script again:
The tool did not run, so config.py does not exist. The agent received a tool message with
status="error" and the redacted reason, so the model can try another way, such as reading the
key from the environment. In skarn guard report the record now reads deny
where it read would-deny. Without a paid license, the binary answers mode="enforce" in audit and the tool
runs. With mode="enforce", the adapter blocks a call the binary cannot answer (a timeout, a
crash, output that is not one verdict), license or not.
An enforced ask is blocked unless you pass on_ask, a function that decides
whether the tool runs. If your agent already uses LangChain's HumanInTheLoopMiddleware,
on_ask is where you hand the decision to it.
A longer run, recorded
The same middleware in a longer scripted run: the agent reads a handoff note that holds an AWS key pair, tries to write the keys into its config, and then writes the config with environment references. In enforce, the guard blocks the first write and allows the second.
Transcript of the film
The film shows this excerpt of agent.py, then runs these commands.
Other runtimes
Each adapter maps the verdict onto the runtime's own way to refuse a tool call:
- OpenAI Agents SDK: a tool input guardrail that answers with
reject_content. - Strands Agents: a plugin; an enforced ask raises an interrupt you can resume.
- Google ADK: a
before_tool_callback. - An MCP server built on the MCP Python SDK: server middleware on
tools/call. - Amazon Bedrock AgentCore Gateway: a request interceptor Lambda.
- LiteLLM proxy: a guardrail, which sees a tool call only in the model's response, so a block rejects that whole model turn.
A runtime with no adapter sends Skarn's own JSON event to skarn guard --agent sdk on
stdin and reads one verdict object back. The guard events reference
describes the event and the verdict.
Audit first, then enforce
Run the agent in audit and read skarn guard report until the flagged calls are ones you
want blocked. A false positive is accepted with the skarn guard accept line the report prints
under it. Enforcement is where your team's policy and baselines decide what blocks, and the guard log is
the record of each block. Install your organisation's license on the server with
skarn license -, which reads the token from stdin, then switch the middleware to
mode="enforce" and redeploy.
In the fleet view
The guard log on the server is the same log the guard writes on a laptop. skarn check
--drop, run on that server, carries its newest enforced deny into the drop it writes, and the
fleet dashboard shows the most recent deny across every machine that reports, servers and laptops alike.
The fleet view is part of the Enterprise tier.
Try it
Install Skarn, then pip install "skarn-guard[langchain]" and run the script above.