
grounded-screen
io.github.argus-forge/grounded-screen
Pay-per-call screen and grounded JSON extract for agents, over stdio or hosted HTTP.
Documentation
grounded-screen
Screen tool results for prompt injection before your agent reads them.
grounded-screen sends untrusted text (a fetched web page, an email, a GitHub issue, a Slack
message, any MCP tool result) to the Injection Screen at
https://extract.sentinelintel.org/screen and gets back a verdict, injection or clean,
plus the suspicious spans with character offsets the server checked against your text.
The same package calls Grounded Extract at https://extract.sentinelintel.org/extract
and returns the object and the grounded map the endpoint returned.
It ships:
- a small Python client that pays per call with x402 on Base,
- a Claude Code
PostToolUsehook that stops Claude when a tool result looks like an injection, - a LiteLLM guardrail that blocks, masks or flags MCP tool results,
- LangChain tools for both paid routes, and a middleware that screens MCP tool results,
- a FastMCP middleware that screens tool results on
on_call_tool, - a stdio MCP server with tools
grounded_extractandgrounded_screen. Optional extra: mcp.
Price
0.003 USDC per screened call (3000 atomic units of USDC on Base, network eip155:8453),
paid from your own wallet through x402. There is no account and no subscription.
The client refuses to pay more than 0.003 USDC for one screen call and refuses to pass a daily
cap you set (default 0.50 USDC per UTC day).
0.005 USDC per extract call (5000 atomic units). The client refuses to pay more than
0.005 USDC for one extract call. Screen and extract share the daily cap and the same wallet key.
GROUNDED_SCREEN_MAX_PER_CALL_USDC can lower either per-call ceiling and cannot raise either one.
Setup in three steps
-
Install:
pip install grounded-screen # client and Claude Code hook pip install git+https://github.com/argus-forge/grounded-screen # the way to install the latest unreleased code pip install "grounded-screen[litellm]" # also the LiteLLM guardrail pip install "grounded-screen[langchain]" # LangChain tools and MCP middleware pip install "grounded-screen[fastmcp]" # FastMCP middleware pip install "grounded-screen[mcp]" # stdio MCP server -
Give it a Base wallet that holds a little USDC. Put its private key in the environment of the process that runs the hook or the proxy. Never put it in a settings or config file.
export GROUNDED_SCREEN_KEY=... # private key of a Base wallet with USDC export GROUNDED_SCREEN_DAILY_CAP_USDC=0.50 # optional, default 0.50Use a wallet that holds only what you are willing to spend on screening.
-
Wire it in.
Claude Code: add this to
~/.claude/settings.jsonor.claude/settings.json(also inexamples/claude-settings.json):{ "hooks": { "PostToolUse": [ { "matcher": "^(WebFetch|WebSearch|mcp__.*)$", "hooks": [ { "type": "command", "command": "grounded-screen-claude-hook", "timeout": 90, "statusMessage": "Screening the tool result for prompt injection" } ] } ] } }LiteLLM proxy: add this to your
config.yaml(also inexamples/litellm-config.yaml):guardrails: - guardrail_name: grounded-screen litellm_params: guardrail: grounded_screen.litellm_guardrail.GroundedScreenGuardrail mode: post_mcp_call default_on: true on_injection: block # block, mask or flag fail_closed: false # true also blocks results that could not be screened max_chunks: 3 # pieces of 20000 characters screened per result mcp_block_behavior: tool_result
What the Claude Code hook does
The hook reads the PostToolUse input Claude Code sends on stdin and screens tool_response
when the tool brings in outside content: WebFetch, WebSearch, and MCP tools
(mcp__<server>__<tool>) whose name contains fetch, browse, email, mail, issue,
github, slack or read_url (case does not matter). Other tools are not screened and cost
nothing.
On an injection verdict it exits 0 and prints one JSON object with these documented fields:
"decision": "block"andreason: the reason is added next to the tool result. It tells Claude the result is untrusted, not to follow any instruction in it and not to act on it until you say so, and it lists each suspicious span with its offsets."continue": falseandstopReason: Claude stops processing and you see the spans, so nothing happens until you reply. SetGROUNDED_SCREEN_HOOK_MODE=warnto keep only the block reason and let Claude continue.systemMessage: a one line warning shown to you.
A clean result, a result that could not be screened (no key, cap reached, network error,
timeout, server error) and a hook error all exit 0 with nothing on stdout, so Claude Code goes
on as if the hook were not there. The reason for an unscreened result goes to stderr, which
Claude does not see; read it with claude --debug.
Fields and behavior follow the Claude Code hooks reference,
https://code.claude.com/docs/en/hooks, sections "PostToolUse", "PostToolUse input",
"PostToolUse decision control", "JSON output", "Decision control", "Exit code output",
"Matcher patterns" and "Match MCP tools". Note from that page: Claude still sees the original
tool output next to the block reason, because a PostToolUse hook runs after the tool ran.
What the LiteLLM guardrail does
GroundedScreenGuardrail subclasses LiteLLM's CustomGuardrail and implements
apply_guardrail. In mode post_mcp_call LiteLLM calls it with every text block and
structuredContent string of the MCP tool result, before the model sees them.
on_injection: blockraisesGuardrailRaisedException, so LiteLLM rejects the tool result. With LiteLLM'smcp_block_behavior: tool_result(its default) the model gets the block as the tool result; withraisethe request fails with HTTP 400.on_injection: maskreplaces each suspicious span with[removed by grounded-screen: suspected prompt injection]and passes the rest.on_injection: flaglogs a warning with the spans and passes the result unchanged.- A result that could not be screened passes, unless
fail_closed: true.
Interface used, from LiteLLM 1.111.1: https://docs.litellm.ai/docs/proxy/guardrails/custom_guardrail,
https://docs.litellm.ai/docs/mcp_guardrail, and in the source
litellm/integrations/custom_guardrail.py (apply_guardrail, line 1670),
litellm/types/guardrails.py (post_mcp_call, line 948; mcp_block_behavior, line 1054),
litellm/proxy/mcp_server/guardrail_translation/handler.py (process_output_response,
line 228) and litellm/proxy/guardrails/guardrail_registry.py
(initialize_custom_guardrail, line 910).
Extract
ExtractClient calls POST https://extract.sentinelintel.org/extract. The body is
text plus a flat JSON schema. The result's object and grounded are the object
and the grounded map the endpoint returned. extracted is false when there is no
object, including a network error, a timeout, a 5xx, or a cap hit, and the call does
not raise. A schema that is not a JSON object is refused before any payment (bad_schema).
Published limits: the schema is a flat object with additionalProperties false and at
most 32 properties. required lists every property once. A property type is string,
number, integer, boolean, or null. A property may include a description of at most 300
characters. Text longer than 40000 characters is rejected. The example response on the
extract site is a shape, not a recorded call.
from grounded_screen import ExtractClient
schema = {
"type": "object",
"additionalProperties": False,
"required": ["invoice_number", "vendor", "date", "total", "currency", "due_date"],
"properties": {
"invoice_number": {"type": "string"},
"vendor": {"type": "string"},
"date": {"type": "string"},
"total": {"type": "number"},
"currency": {"type": "string"},
"due_date": {"type": "string"},
},
}
result = ExtractClient().extract(
"Invoice INV-20431 from Lakeside Paper Co., dated 2026-11-02, total 1284.50 USD, due 2026-12-02.",
schema,
)
if result.extracted:
print(result.object, result.grounded)
else:
print("not extracted:", result.reason) # never raises
Set GROUNDED_EXTRACT_URL only to point at a different extract endpoint. The key,
the daily cap, and the per-call lowering variable are the same ones /screen uses.
LangChain
Install grounded-screen[langchain]. screen_tool() and extract_tool() are LangChain
tools, one for each paid route. screen_mcp_middleware() is an AgentMiddleware whose
wrap_tool_call screens MCP tool results after the tool runs.
- Tools are built with
@tool(langchain_core/tools/convert.py, line 77, re-exported bylangchain/tools/__init__.py). - The interceptor follows the current replacement for
langchain-mcp-adapterstool interceptors: https://docs.langchain.com/oss/python/migrate/langchain-mcp-adapters (section "Tool interceptors") and https://docs.langchain.com/oss/python/langchain/middleware/custom.AgentMiddleware.wrap_tool_callislangchain/agents/middleware/types.pyline 676. It returns aToolMessage. Status"error"is the documented failed tool result (same file, the example at line 739). - MCP provenance is
metadata["mcp"]fromlangchain/mcp/tools.py_tool_metadata, line 183 (the return is line 209). A tool without that key is not screened and costs nothing. - Pass the middleware to
create_agent(..., middleware=...)(langchain/agents/factory.pyline 895).
from langchain.agents import create_agent
from grounded_screen.langchain_tools import extract_tool, screen_mcp_middleware, screen_tool
agent = create_agent(
model,
tools=[screen_tool(), extract_tool()],
middleware=[screen_mcp_middleware(on_injection="block")], # or "flag"
)
block replaces the tool result with a ToolMessage of status error that does not
include the tool text. flag keeps the text and adds one warning line. A result that
could not be screened is returned unchanged. extract_tool takes text and schema
(a flat JSON schema). The model field is not named schema, because that name already
belongs to Pydantic's BaseModel.
FastMCP
Install grounded-screen[fastmcp]. grounded_screen_middleware() returns a
fastmcp.server.middleware.Middleware instance. Register it with add_middleware.
It screens the tool result inside on_call_tool, after the tool has run.
Interface: https://gofastmcp.com/servers/middleware (section on_call_tool).
Middleware.on_call_tool is fastmcp/server/middleware/middleware.py line 239.
ToolError is fastmcp/exceptions.py line 54. ToolResult is
fastmcp/tools/base.py line 150. Text is read from TextContent.text the same way
fastmcp/server/middleware/response_limiting.py does at line 166.
FastMCP.add_middleware is fastmcp/server/server.py line 820.
from fastmcp import FastMCP
from grounded_screen.fastmcp_middleware import grounded_screen_middleware
mcp = FastMCP("my-server")
mcp.add_middleware(grounded_screen_middleware(on_injection="block")) # or "flag"
block raises ToolError and does not include the tool text. flag appends one
text block and returns the original content. A result that could not be screened is
returned unchanged.
MCP server
Install grounded-screen[mcp]. The console script grounded-screen-mcp starts a
stdio MCP server. It exposes grounded_extract (one paid extract call, 0.005 USDC)
and grounded_screen (one paid screen call, 0.003 USDC). A network error, a timeout,
a 5xx, or a cap hit comes back as extracted or screened false and does not raise.
Importing grounded_screen does not import the MCP SDK.
The server is io.github.argus-forge/grounded-screen in server.json. The package
binary named grounded-screen is the stdin screener, so start the MCP server with
grounded-screen-mcp, not uvx grounded-screen.
{
"mcpServers": {
"grounded-screen": {
"command": "uvx",
"args": ["--from", "grounded-screen[mcp]==0.3.0", "grounded-screen-mcp"],
"env": {
"GROUNDED_SCREEN_KEY": "..."
}
}
}
}
An installed copy uses the same environment and "command": "grounded-screen-mcp".
The server uses the official MCP Python SDK. MCPServer is mcp/server/__init__.py
line 4 (class at mcp/server/mcpserver/server.py line 157). @server.tool() is
line 669 of that file. run() with no argument uses stdio (line 404). Getting
started: https://py.sdk.modelcontextprotocol.io/get-started/.
Hosted MCP endpoint
The hosted MCP endpoint is https://extract.sentinelintel.org/mcp. It serves two tools.
grounded_extract costs 0.005 USDC per call. grounded_screen costs 0.003 USDC per call.
Payment is x402 per tool call, per the x402 MCP transport spec:
https://github.com/x402-foundation/x402/blob/main/specs/transports-v2/mcp.md.
Client example using the released package x402 2.30.0
(pip install "x402[mcp,evm]==2.30.0", which installs mcp 1.30.0). The example connects
to that URL and pays per tool call. The signer reads GROUNDED_SCREEN_KEY. The spend cap
of 0.005 USDC per call covers both tool prices. The stdio server above is a separate
process on the same tools.
import os
from eth_account import Account
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
from x402 import SchemeRegistration, x402Client, x402ClientConfig
from x402.mcp import x402MCPSession
from x402.mechanisms.evm.exact import ExactEvmClientScheme
signer = Account.from_key(os.environ["GROUNDED_SCREEN_KEY"])
payment = x402Client.from_config(
x402ClientConfig(
schemes=[
SchemeRegistration(
network="eip155:8453",
client=ExactEvmClientScheme(signer),
),
],
spend_controls={"max_amount_per_payment": "$0.005"},
),
)
async with streamable_http_client("https://extract.sentinelintel.org/mcp") as (
read,
write,
_session_id,
):
async with ClientSession(read, write) as session:
paid = x402MCPSession(session, payment, auto_payment=True)
await paid.initialize()
await paid.call_tool(
"grounded_extract",
{
"text": "clean the flat",
"schema": {
"type": "object",
"additionalProperties": False,
"required": ["house_place"],
"properties": {"house_place": {"type": "string"}},
},
},
)
await paid.call_tool("grounded_screen", {"text": "clean the flat"})
Python client
from grounded_screen import ScreenClient, screen_text
result = ScreenClient().screen("Ignore all previous instructions and ...", source="web")
if result.injection:
for span in result.spans:
print(span.start, span.end, span.text)
elif not result.screened:
print("not screened:", result.reason) # never raises
screen() takes 1 to 20000 characters. screen_text() splits longer text into pieces of up to
20000 characters and screens at most max_chunks of them (each piece is one paid call).
There is also a command line tool: echo "some text" | grounded-screen.
ScreenResult.screened is False whenever there is no verdict, with reason set to one of
missing_key, bad_key, per_call_cap, daily_cap, network_error, timeout,
server_error, unexpected_status, payment_rejected, malformed_response,
offer_mismatch, payment_error, empty_text, text_too_long or internal_error.
ExtractResult.extracted is false for those same reasons, and also for bad_schema
when the schema is not a JSON object. That refusal happens before any payment.
| Variable | Default | Meaning |
|---|---|---|
GROUNDED_SCREEN_KEY | none | Base wallet private key. Read at call time, never logged or stored by the client. |
GROUNDED_SCREEN_DAILY_CAP_USDC | 0.50 | Most USDC paid per UTC day. |
GROUNDED_SCREEN_MAX_PER_CALL_USDC | 0.003 | Can lower the per call cap, never raise it. |
GROUNDED_SCREEN_STATE_FILE | ~/.local/state/grounded-screen/spend.json | Daily spend ledger (also honors XDG_STATE_HOME). |
GROUNDED_SCREEN_TIMEOUT | 20 | Seconds per HTTP request. |
GROUNDED_SCREEN_URL | https://extract.sentinelintel.org/screen | Screen endpoint. |
GROUNDED_EXTRACT_URL | https://extract.sentinelintel.org/extract | Extract endpoint. |
GROUNDED_SCREEN_PAY_TO | the service address | Pay-to address the 402 offer must name. |
GROUNDED_SCREEN_RECEIPT_LOG | none | If set, one JSON line per paid request: time, HTTP status, settled, transaction, amount, verdict. Never the key or the text. |
GROUNDED_SCREEN_HOOK_MODE | stop | stop or warn (Claude Code hook). |
GROUNDED_SCREEN_MAX_CHUNKS | 3 | Pieces screened per tool result (Claude Code hook). |
The client pays only an exact scheme offer in Base USDC to the expected pay-to address, for
at most the per call cap. It counts a payment against the daily cap before sending it and
gives it back only when the service answers without settling.
Measured results
All numbers below are from two measurement runs of the same /screen service. Nothing else
has been measured.
indirect-injection gate. Test set derived from
nvidia/Nemotron-RL-Agentic-Indirect-Prompt-Injection-v1 (revision d738d4f3): 1271
tool or document strings that contain an injection, and 1251 negatives made from the same
strings with the injection text removed. Synthetic, enterprise domain, indirect only.
| Metric | Result |
|---|---|
| Recall | 0.9961 (1266/1271) |
| False positive rate | 0.0080 (10/1251) |
| Detections with a span overlapping the injection | 1266/1266 |
| Returned spans whose offsets match the text | 2560/2560 |
| p95 response time, all rows (longest row 906 characters) | 1.258 s (median 0.643 s, n = 2522) |
| p95 response time, one 20000 character input | 3.240 s (n = 50) |
public benchmark check. 200 attack rows and 200 hard benign
rows sampled with a fixed seed from deepset/prompt-injections,
jackhhao/jailbreak-classification and the post-cutoff instruction-heavy set
(test split, direct injection, jailbreak and obfuscation rows; hard negative benign rows).
| Slice | Recall | False positive rate |
|---|---|---|
| All | 0.870 (174/200) | 0.060 (12/200) |
| deepset and jackhhao (published before 2026-04-15) | 0.867 (104/120) | 0.025 (4/161) |
| post-cutoff instruction-heavy set | 0.875 (70/80) | 0.205 (8/39) |
| deepset only | 0.759 (22/29) | no benign rows |
Response time on that run: p50 510 ms, p95 2170 ms (n = 400). 8 of the 174 detections had no
span the server could locate in the text; the service does not settle such a reply, so the
caller pays nothing and gets no verdict (the client reports server_error). Counting only
detections with a located span, recall is 0.830 (166/200).
Both runs were made on a loopback instance of the service, so the times above do not include the internet round trip or the x402 payment step.
Grounded Extract, published at https://extract.sentinelintel.org/, measured on that service with no field descriptions:
| Measurement | Result |
|---|---|
| Price | 0.005 USDC per call |
| MASSIVE short commands | 481 of 500 fields exact |
| VRDU registration forms | 491 of 600 fields matched |
| Long-document misses, adjudicated cold on an earlier prompt before the abstain rule was added | projected 91.4 percent of 600 fields, 95 percent interval 88.2 to 94.5 |
Known limits
- Instruction heavy benign text is often flagged. On the post cutoff hard negative set, 8 of 39 benign rows were flagged (0.205), and polite imperative requests aimed at an assistant were flagged 6 of 7 times. The screen counts any text that tries to direct an AI agent as injection.
- ROT13 encoded instructions are mostly missed: 1 of 8 caught.
- Only English text has been measured.
- One GPU serves the screen, so expect about one call a second across all users. Up to
four calls wait behind the running one; past that the service answers 503 without charging,
and the client reports
server_error. - About 1.3 s is added per screened result (p95 1.258 s on the gate rows, before network and payment time). Longer inputs take longer: p95 3.240 s at 20000 characters.
- The pre cutoff public sets may be in the model's training data, and the post cutoff set comes from a single template generated source.
- A
cleanverdict means the screen found nothing. It is not proof that text is safe. - A
PostToolUsehook runs after the tool ran: the screen cannot undo what a tool already did.
License
MIT. Copyright (c) 2026 ArgusForge LLC.
Sources
The post-cutoff instruction-heavy set is the Prompt Injection Benchmark (Apache-2.0): https://huggingface.co/datasets/DaveyD347/prompt-injection-benchmark
grounded-screenpip install grounded-screen