Implements before_agent / abefore_agent (per-invocation trace setup) and wrap_tool_call / awrap_tool_call (the tool-boundary gate). Sync and async agent runs both work.
Read intent
The service reads a top-level intent field on the /decide body as its highest-precedence intent signal and records the classification on the decision trace. The current judge doesn’t change verdicts on it, so declaring reads doesn’t fast-pass anything today — it puts your read/write taxonomy on every trace, scoped by the tool_post-only rule below. Declaring which tools are reads lets the middleware assert intent="read" on exactly those calls.Declare the read taxonomy once at construction. Either enumerate the read tools, or supply a resolver for a computed taxonomy:
from tenet_langchain import TenetJudgeMiddlewaremw = TenetJudgeMiddleware( judge, policy=policy, judge_tools_pre={"schedule_interview", "send_phone_screen"}, # mutating → pre judge_tools_post={"list_candidates", "get_application"}, # reads → post read_tools={"list_candidates", "get_application"}, # ← stamps intent="read" # or, for a computed taxonomy (wins over read_tools): # intent_resolver=lambda tool_name: "read" if tool_name.startswith("get_") else None,)
The intent wire field takes read | action | unknown (default unset == unknown, omitted from the body). read / action are emitted; unknown / None are omitted so the envelope is byte-identical to not sending the field. An intent_resolver must return one of those strings or None; an out-of-vocab value raises ValueError.
Safety contract — tool_post-only, enforced in code
A caller-asserted intent="read" is stamped only at phase == "tool_post" for a tool in read_tools (or one the resolver classifies as read). It is never emitted at agent_input or tool_pre — even when the tool name is in read_tools.
The middleware applies the phase gate before it consults read_tools / intent_resolver. It stamps intent="read" only at tool_post; the field is never sent at agent_input or tool_pre, whatever read_tools contains.Full field semantics and the wire header: Read-intent contract.Every call the middleware makes is judged under the client’ssurface — there is no per-tool surface option. For agents whose tools span recruiting-action kinds, scope one middleware per action family via judge_tools_pre / judge_tools_post (one client per surface), or gate mixed tools with tenet_client’s evaluate(surface=...).An include_with_caveats verdict rides through as a non-blocking allow: the judge’s advisory note is folded onto ctx.metadata and annotated onto the proceeding tool result’s response_metadata (status preserved, never an error). It never reaches on_review and never interrupts. On streaming runs (stream=True), severity-routed dispatch waits for the final severity, not the provisional verdict event — see Verdict-first streaming.
Tell the judge what the tool does
The judge sees a tool call as its arguments and little else, so it can misread a call whose meaning sits in the user’s words or in the tool’s purpose. The request-shaping options add those facts without subclassing the client.
from tenet_langchain import JudgeCall, RequestShape, TenetJudgeMiddlewaredef shaper(call: JudgeCall) -> RequestShape | None: # Runs for every judged call, including agent_input; non-None fields win. return RequestShape(context={"role": current_page.job_title})mw = TenetJudgeMiddleware( judge, policy=policy, surface_for_tool={"rank_candidates": "resume_triage_rank"}, # per-call surface tool_descriptions={"rank_candidates": "Ranks applicants for the open role."}, send_user_prompt_on_tool_phases=True, # the user's own words, not a dump of the args request_shaper=shaper,)
surface_for_tool: the surface for a listed tool at tool_pre / tool_post;
other tools use the client’s surface.
tool_descriptions: sent as context["tool_description"] for a listed tool.
send_user_prompt_on_tool_phases: the latest user message goes out as
user_prompt= (the judge’s recruiter_prompt) on tool phases, unless the tool’s
own arguments already carry a recruiter_prompt.
request_shaper: gets a JudgeCall (phase, tool name, input, output, latest user
message, graph state, runtime) and returns a RequestShape (surface, context,
user_prompt, candidate_content) or None. context is merged over the default
context; candidate_content= is how the output of a tool is judged as candidate
text. A shaper that raises propagates, so a bug is never silently sent unshaped.
Reserved context keys (tool_name, recruiter_prompt, …) are still rejected by the
client with ValueError; use user_prompt / candidate_content for those. The
verdict cache key includes whatever was shaped. If you also call the client directly,
default_judge_context(tool_name, tool_input) returns the same default context the
middleware builds for that call, and RESERVED_CONTEXT_KEYS lists the names to keep out.max_tool_output_chars (default None, no cap) cuts the tool output sent to the
judge at tool_post to that many characters, because large outputs drive judge
latency. The cut applies to the judge’s copy only: the tool_output a
request_shaper sees and the verdict cache key use the cut text, while the tool’s
real result returned to the agent and the JudgeContext.tool_output your policy
callbacks receive stay whole. Must be >= 1.send_user_prompt_on_tool_phases is silently a no-op for a call whose arguments
already carry recruiter_prompt: the judge reads the arguments’ own ask.
These options change what the judge reads, so they can change verdicts. Turn them on in a test environment and compare before production.
Record every decision
You can’t tune a policy you can’t see. on_decision hands you one record per judged call.on_decision takes a sink, or a list of sinks, and gets one DecisionRecord per
judged call after the policy has chosen an action. outcome is that action’s kind
(allow, block, tool_error, retry_nudge, …), turn_approved when turn
approval passed the call, interrupted when a review callback paused the run, or policy_error (with
extra={"error": "<ExceptionName>"}) when a policy callback raised any other
exception; that exception is then re-raised unchanged. A cache hit carries extra={"cached": True}; with the judge unavailable
decision is "unavailable" and outcome is what the policy did. A failing sink
is logged and never affects the run.
trace_id_provider returns the run’s trace id (32 hex characters), so
record.trace_id is your own trace and langfuse_score_sink scores it. None or an
invalid value falls back to a generated id. Trace ids do not reach Tenet; they live
on the client call, JudgeContext and the record.A human-review pause writes an interrupted record, and the resumed pass writes
another (marked cached when cache_verdicts is on), so a paused review yields two.
Try it before you enforce it
“What would the judge do to my traffic?” should not need enforcement to answer. Shadow mode judges every phase without acting on it.“What would the judge do to my traffic?” should not need enforcement to answer.
With mode="shadow" every phase the middleware would judge is judged without
acting: the policy is never dispatched, the hooks return as if the call were
allowed, and each check ends in one DecisionRecord with mode="shadow" and
outcome set to the verdict (allow, caveat, review, block, degraded,
unavailable, or skipped). Nothing is cached, approved or written to review
state.
Async hooks (ainvoke / astream) judge in a background task and never wait for
the answer. Sync hooks judge inline under shadow_timeout_s (default 15 seconds),
which adds that latency to the turn, so prefer async. A judge that fails or misses
the deadline is recorded as unavailable; a shadow check never raises into the turn.
stream=True is ignored in shadow mode. shadow_timeout_s must be a finite number above
zero. If your is_user_message raises in shadow mode, the error is logged and that check is
skipped. with_human_review(..., mode="shadow") raises ValueError: it would build a review
recipe that never reviews.A consumer of the records should filter on outcome: a skipped check is recorded with
decision="unavailable" like a judge outage, and only outcome tells them apart.Shadow checks share the judge’s capacity with checks that block, and a burst of them
once tripped the engine’s circuit breaker. A ShadowRunner therefore allows only
max_in_flight=2 checks at a time and skips the rest (recorded with
outcome="skipped", extra={"reason": "in_flight_limit"}); a skipped check is
never queued. The default runner is one per process, so apps that build the
middleware per request share a single cap. Pass shadow_runner=ShadowRunner(...)
to use your own, and call await default_shadow_runner().drain() at application
shutdown so checks in flight finish.Shadow checks never open or close the client’s circuit breaker (they are sent with
record_breaker=False), so a fault only the shadow checks see cannot fail a real turn,
and their successes do not reset the enforcing checks’ failure count. They are skipped,
with no network call, while the breaker is open.The cap applies to the async hooks only: sync shadow hooks run inline and are not capped.
The records of checks still in flight are lost if the event loop closes without a
drain() (a script that ends right after asyncio.run(...) sees none), and drain()
waits only for the checks of the loop that calls it.To record a verdict on the agent’s final reply (phase="agent_output"), add the
reply check:
middlewares() returns [mw, RefusedExchangeFilter?, AgentOutputCheck(...)] (the
filter only when refusal_marker is set), sharing the sinks, request shaper and
runner. The check’s middleware name derives from the parent’s name=, so two named
judges can share one agent. AgentOutputCheck is a separate class so users who do not turn
it on pay no extra graph node per model call. It checks only a model message with
text and no tool calls (not the canned text of a block), sends it as agent_reply=
with the user’s latest message as user_prompt=, and only observes: mode="enforce"
is not supported, since holding or retracting a streamed reply is a product decision
for your app. A request_shaper receives a JudgeCall with phase="agent_output",
the reply as tool_input, and the user’s ask as user_message.
Make sure every tool is classified
A tool added later and listed nowhere would run with no check and no warning. strict_tools turns that into a deploy-time error.The middleware judges by tool name, so with judge_tools_pre / judge_tools_post set, a
tool added later and listed nowhere runs with no check and no warning. Classify every tool:
judged (judge_tools_pre, judge_tools_post), a read (read_tools), or deliberately not
judged (unjudged_tools, a mapping from tool name to the reason, or just names). Leaving a
phase list unset (None) means every tool is judged at that phase, so name both lists.
mw = TenetJudgeMiddleware( judge, judge_tools_pre=["send_email"], judge_tools_post=["send_email"], read_tools=["search_candidates"], unjudged_tools={"move_stage": "ids and a stage name only; the ask behind it is judged"}, strict_tools=True,)
With strict_tools=True, a call to a tool that no enabled phase judges, and that is neither in
read_tools nor in unjudged_tools, does not run: the tool wrapper raises
UnclassifiedToolError naming the tool. “Judged” is what the wrapper itself decides: the
phase’s check_pre / check_post is on and its list is unset (every tool) or names the tool.
A disabled phase covers nothing, and an unset list covers every tool only at an enabled phase.
So with judge_tools_pre=["a"], the post list unset and check_post on, an unlisted tool is
judged at post and runs; with check_post=False it raises. It applies in mode="shadow" too,
since the point is to find the tool before you enforce. A tool both judged and in
unjudged_tools raises ValueError at construction.The error is a deploy-time guard, not a recovery path. Raised in the middle of a turn it leaves
the thread with an assistant tool call that has no result (the tool did not run), which a
provider rejects on the next turn. Use assert_tools_classified in a test so it fires before
production.Catch it in CI rather than in production, with one line in your test suite:
It raises UnclassifiedToolError listing every unclassified tool, and every name in a list
that no tool carries (a stale entry after a rename). mw.tool_classification(all_tools)
returns the label per tool: pre, post, pre+post (enabled phases only), read, unjudged or
unclassified. Both accept anything create_agent does as a tool: a BaseTool, a plain
function, a provider dict tool (skipped when it has no name) or a name.
Recursion limit
create_agent turns each node hook a middleware overrides into a graph node, and each node
run uses one LangGraph recursion step. TenetJudgeMiddleware costs one step per run
(before_agent) plus one per model call (before_model), whether or not
check_user_messages is on; tool judging costs none. AgentOutputCheck costs one more per
model call. RefusedExchangeFilter costs none (recursion_steps returns 0), and
judge_unanswered_messages adds none: it is the same node judging more messages. A turn
near your recursion_limit can fail with GraphRecursionError unless you add the cost:
max_model_calls = 16middleware = mw.middlewares(check_agent_output="shadow")limit = 50 + sum(m.recursion_steps(model_calls=max_model_calls) for m in middleware)agent.invoke(inputs, {"recursion_limit": limit})
Human review
A review or block verdict can pause the agent for a person and resume from the answer, which needs a checkpointer and a stable thread_id.
from langchain.agents import create_agentfrom langgraph.checkpoint.memory import InMemorySaverfrom langgraph.types import Commandfrom tenet_client import TenetCloudJudgeClientfrom tenet_langchain import APPROVE, TenetJudgeMiddleware, interrupt_policyjudge = TenetJudgeMiddleware.with_human_review( TenetCloudJudgeClient.from_env(), policy=interrupt_policy(strict_approve=True), # only an explicit approve approves a message)agent = create_agent( model="claude-sonnet-4-5-20250514", tools=[send_claim_to_payer], middleware=judge.middlewares(), checkpointer=InMemorySaver(),)config = {"configurable": {"thread_id": "case-123"}}result = agent.invoke({"messages": [{"role": "user", "content": "Submit the packet."}]}, config=config, version="v2")if result.interrupts: prompt = result.interrupts[0].value # show prompt["display_message"] and prompt["choices"] agent.invoke( Command(resume={**APPROVE, "review_id": prompt["review_id"]}), config=config, version="v2", )
The prompt is format_review_event(...).to_dict() plus phase, review_id and, for a message,
user_message. Ways to answer:
{"action": "approve", "review_id": ...} approves (APPROVE is the first part).
{"selection": "<text>"} at a message replaces it with that text, which is judged in turn. It is
not an approval and leaves no approval behind. Anything else at a tool asks again.
A block can only be dismissed; no answer lets it through.
A message the judge reports as an attack on the agent (a SAFETY- label) gets no prompt: the turn
ends with DEFAULT_REFUSAL_MESSAGE, and that exchange is hidden from later judge calls and the
model. Set refuse_label_prefixes=() to turn that off.
Echo review_id. Without it, a resume that lands where the judge reports a different finding for
the same call approves the one the person never saw. A client that does not echo it still works.
At a message, any non-approve answer approves by default (what existing clients rely on); the recipe
above passes interrupt_policy(strict_approve=True), which you should do in a new integration so
only approve does. review_id binds an answer to the kind of finding (phase, tool name, labels), not to the message
text or the tool arguments. Keep tools idempotent: LangGraph re-runs the node that paused, from the top, on resume.with_human_review sets check_user_messages, cache_verdicts, turn_approval,
persist_review_state, rejudge_overridden_input, judge_unanswered_messages (a flagged message
whose pause the app abandons by sending a new message cannot reach the model unapproved) and
refusal_marker=DEFAULT_REFUSAL_MESSAGE; every one can be overridden by keyword. To change the
refusal text, pass with_human_review(..., refusal_message="..."): the one string goes to both
the policy and refusal_marker. If you pass your own policy= built with interrupt_policy(...)
(display=, payload=, accept_rewrite=, refusal_message=, block_message=, on_action=,
plus any JudgePolicy option) and also a refusal_marker, you own keeping the two the same.
on_action(name, ctx, verdict) hears paused, approved, rewritten, blocked, refused and
replayed_answer_skipped; approved and rewritten are reported once per decision (a second message approved, or one
message rewritten twice, reports again) even though LangGraph re-runs the node that paused, from
the top, on resume. A review that gets no usable answer 25 times in a row raises RuntimeError. Keep tools idempotent for the same
reason.
Reviews that survive a restart
By default the middleware remembers “this message was judged” and “the user
approved this finding for this turn” in memory on the instance. Turn on
persist_review_state=True when you run with a checkpointer and more than one
process, or rebuild the agent for every request: a resume that lands on a new
instance would otherwise judge the approved message again, and a tool that
raises the same finding would pause the user a second time.
Four private graph-state channels hold the state; they never reach the caller’s output. Messages without an id are judged every time. Two middleware instances that should not share state need different review_state_prefix and name= values.The default policy (no on_review) allows a review, so with persisted state that
allow is recorded as a reviewed id and a turn approval, with no human involved:
the message is then left out of later history. Pass an on_review that pauses if
that is not what you want.
Rewrites and refusals
Two options for a human-review flow, whatever policy drives it.rejudge_overridden_input=True. When the policy answers override_input at the
model boundary (for example the user picked a suggested rewrite), the default is
to swap in the new text and go straight to the model: the new text is never
judged, and the replacement drops the original message’s id and kwargs, so the
thread no longer shows which message was replaced. With the option on, the
replacement keeps the original’s id and additional_kwargs (plus
additional_kwargs["tenet_rewrite"] = True) and is judged as the new
agent_input before the model runs, again through your policy. A rewrite may be
overridden again; after three replacements the next override_input ends the turn
with “The rewritten message could not be approved.” An override_input never
records a turn approval, and with persist_review_state the message id is
recorded as allowed only after the final allow. The replacement must itself be
the message that is judged: if is_user_message would not accept the replacement
text, the turn ends with the same “could not be approved” message instead of
judging some other message.judge_unanswered_messages=True (needs persist_review_state=True). A flagged
message pauses the graph. If the app then sends a new message on the same thread
instead of resuming, the default is to judge only the latest message, and the
model receives the flagged one as history without an approval ever given. With the
option on, every user message after the last assistant message (per
is_user_message, refused exchanges excluded) that is not already recorded as
allowed is judged, oldest first, as agent_input. The first whose action is not
an allow decides the turn, and a pause is about that message; the model runs only
when all are allowed. A rewrite replaces whichever message was being judged. The block, refusal and
cap messages the middleware writes carry additional_kwargs["tenet_answers"] (the
id of the message they answer), so a message that sat before such a reply is still
judged on the next turn, and one the reply already answers is not judged again. The
tag is written only when judge_unanswered_messages is on or a refusal_marker is
set; with neither, the stored messages are what earlier releases wrote.The option covers the messages after the last model reply. An in-place edit of a
message that was already answered (same id, new text, before the last reply) is not
re-judged, the same as without the option. Cost is one judge call per unanswered
message, so a thread restored with many unanswered messages is judged that many times
on its first turn. When several flagged messages are queued, each resume re-judges the
earlier ones (the node’s record of them is lost at every pause) unless the verdict
cache is on (cache_verdicts).refusal_marker="...". When a message is an attack on the agent and the turn ends
with a fixed refusal, that exchange would otherwise stay in the conversation: with
send_history the judge flags every later message with the old turn as evidence,
and the refused instruction reaches the model on the next allowed turn. Set the
marker to the exact refusal text (DEFAULT_REFUSAL_MESSAGE is a ready one) and
return it from your block action. An AIMessage equal to the marker, with the
user message it refused, is a refused exchange (the message named by its
tenet_answers tag, or, for a reply with no tag, the user message right before it): it is left out of the history
sent to the judge, is never “the latest user message”, and is removed from every
model request. The checkpoint keeps it, so the transcript still shows it. The
marker is matched against stored transcripts: never reword it once it is in
production, or old refusals come back into the conversation.The policy-authored refusal (a block or tool-error message equal to the marker, and
the “could not be approved” message after a rewrite cap) is also tagged
additional_kwargs["tenet_refusal"] = True. An exchange counts as refused when its
reply carries the tag or equals the marker exactly, so threads stored before this
option, which have only the text, still match. A model reply that happens to equal
the marker hides the user message before it too; that is known and low
consequence.The model request is cleaned by a separate middleware, RefusedExchangeFilter.
Hand create_agentmw.middlewares() rather than [mw]: it returns [mw] when
no marker is set, and [mw, RefusedExchangeFilter(mw)] when one is. The filter adds
a model-call wrapper (an edge and a trace span per model call) only when you opt in;
its name derives from the judge’s name=, so two named judges can share an agent.
With a marker set and only [mw] passed, the first model call raises a
RuntimeError rather than letting refused text reach the model silently. The
filter changes the model request only: the checkpoint still holds the refused
exchange, so other middleware that reads state (a summarizer, say) still sees it.
If every message left is a refused exchange, the turn ends without calling the
model.
When a thread id is configured (a checkpointer plus
{"configurable": {"thread_id": ...}}), one middleware instance is safe to
share across concurrent conversations: trace ids, retry-nudge budgets, the
verdict cache and turn approvals are all scoped to the thread. Without a thread
id every run shares one scope, as a single-conversation instance does.Per-thread state is bounded: TenetJudgeMiddleware(judge, max_threads=1024)
keeps the 1024 most recently used threads and evicts the least recently used
beyond that. Evicting a thread drops its cache, approval, trace and retry-nudge
counters. A thread’s trace id is constant within a run while the thread stays
among the max_threads most recently used; an evicted thread starts a new
trace on its next tool call.
Timeouts
A timeout reaches on_timeout; if you leave it unset, a timeout falls back to on_unavailable, so setting only on_unavailable covers both.
ToolGuardMiddleware
Constructor-injected tool allowlist — structural defence-in-depth that stops the model from calling tools the application never registered, at the agent layer, instead of scanning model output for leaked tool names after the fact.
from langchain.agents import create_agentfrom tenet_langchain import ToolGuardMiddlewareTOOLS = [search_tool, send_email_tool, delete_db_tool]TOOL_NAMES = frozenset(t.name for t in TOOLS) # one source of truthagent = create_agent( model="...", tools=TOOLS, middleware=[ToolGuardMiddleware(allowed=TOOL_NAMES)], context_schema=RequestContext, # optional — a `scopes: frozenset[str]` field)
Two layers enforce independently:
Layer 1 — wrap_model_call: per-request scoping. Narrows the tools the model sees to the subset permitted by runtime.context.scopes. No-ops cleanly when context or scopes is absent, so Layer 2 stays the unconditional enforcement point.
Layer 2 — wrap_tool_call: hard enforcement. Any call whose name is not in the constructor allowed set short-circuits with ToolMessage(status="error") — the handler is never invoked, regardless of how the call surfaced. Comparison is by tool name (string), not object identity.
The allowlist lives on the instance (constructor), never written to messages or AgentState, so it is never serialized into the prompt or captured in checkpoints/traces. Both sync and async (awrap_tool_call) are implemented. It does not validate tool arguments (an allowed tool with poisoned args passes) — compose with argument validation or HumanInTheLoopMiddleware on high-impact tools.
Adjacent classes
Class
Status
Use when
TenetJudgeMiddleware
Current
create_agent integrations — always start here
TenetMiddleware
Separate product
Local Tenet server for PII detect/redact — not the cloud judge
TenetCallbackHandler / AsyncTenetCallbackHandler
Adjacent
Non-middleware LangChain chains; hooks on_tool_start / on_tool_end against the local server
TenetGuard
Adjacent
Standalone PII detection on arbitrary text (detect_pii)
HITL display helpers
For harnesses that surface review verdicts to humans:
RiskLabelDisplay + DEFAULT_EEO_TOPIC_MAPPING — render risk codes (EEO-AGE-PROXY-01 → “age-discrimination”) as reviewer-friendly topics; operator-only codes map to None and drop out.
ReviewEvent + format_review_event — a transport-ready review record with to_sse() / to_dict() renderers. The middleware never calls these; your app does, from its HITL handler.
Full usage — callbacks, SSE rendering, resume semantics — in the HITL guide.These pair with an interrupt()-based on_review callback (Human in the loop) and turn_approval=True: the human approves once, and approved risk labels don’t re-trigger for the rest of the turn.
Re-exports
JudgePolicy, JudgeVerdict, JudgeContext, JudgeAction, and judged re-export from tenet_client — import from either package.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Tenet Labs","description":"Tenet Labs documentation — Tenet Guardrails (hosted guardrails for agent tool calls, served by the Judge API) and PII Engine (Enterprise), de-identification that runs in your own AWS account.","colors":{"primary":"#254BB0","light":"#7B9AEB","dark":"#1A3A8F"},"logo":{"light":"https://mintcdn.com/tenetlabs/Ux15lHnF6gElpQTR/logo/light.svg?fit=max\u0026auto=format\u0026n=Ux15lHnF6gElpQTR\u0026q=85\u0026s=ad2a07649adcf4d8be428b5187f69dd3","dark":"https://mintcdn.com/tenetlabs/Ux15lHnF6gElpQTR/logo/dark.svg?fit=max\u0026auto=format\u0026n=Ux15lHnF6gElpQTR\u0026q=85\u0026s=63483a7e8bc79fe2d8552c527fb1f187","href":"https://tenetlabs.com"},"favicon":"https://mintcdn.com/tenetlabs/f83ct0NG_FFBa-fQ/favicon.svg?fit=max\u0026auto=format\u0026n=f83ct0NG_FFBa-fQ\u0026q=85\u0026s=cb379042881580f3b646d44dc107ca17","navbar":{"links":[{"href":"mailto:team@tenetlabs.com","label":"Support"}],"primary":{"type":"button","label":"Get API keys","href":"https://platform.tenetlabs.com"}},"footer":{"socials":{"github":"https://github.com/tenetlabsdev"}},"fonts":{"heading":{"family":"DM Sans"},"body":{"family":"IBM Plex Sans"}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","add-mcp","cursor","vscode","windsurf"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"tenetlabs","hasAudioNarration":false,"actualSubdomain":"tenetlabs","customDomains":["docs.tenetlabs.com"],"gitSource":{"type":"github","owner":"tenetlabsdev","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":"","_id":"6b10eb819ffae5051c4157e3"},"feedback":{"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6b0c81caf742bc3f276814f0","clientVersion":"0.0.4450","searchFilterCounts":[{"language":"default","tag":"Documentation","count":42},{"language":"default","tag":"PII Engine (Enterprise)","count":30},{"language":"default","tag":"Tenet Guardrails","count":29},{"language":"default","tag":"API Reference","count":16},{"language":"default","tag":"Concepts","count":10},{"language":"default","tag":"Getting Started","count":9},{"language":"default","tag":"Guides","count":7},{"language":"default","tag":"Operate","count":7},{"language":"default","tag":"Judge API","count":7},{"language":"default","tag":"PII Engine API","count":7}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":true,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"email":"team@tenetlabs.com","showHelpButton":true}},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"auth-vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[{"_id":"6a29da138cafb8a43c371463","deploymentId":"6a14c5b5c81d589b95bf2b49","questionText":"How do I add guardrails to my agent?","status":"active","generatedBy":"manual","createdAt":"2026-06-10T21:41:39.491Z","updatedAt":"2026-06-10T21:41:39.491Z","__v":0}],"googleFontsInlined":true},"customCss":[]}
{"page":{"pagePath":"sdk/tenet-langchain","slug":"/sdk/tenet-langchain","pageMetadata":{"title":"tenet-langchain","description":"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.","href":"/sdk/tenet-langchain"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`tenet-langchain`})}),`: LangChain adapters over `,_jsx(_components.code,{children:`tenet-client`}),`. Requires `,_jsx(_components.code,{children:`langchain>=1.2.13`}),` (the `,_jsx(_components.code,{children:`AgentMiddleware`}),` API), Python 3.11–3.13. Version 0.7.0 needs `,_jsx(_components.code,{children:`tenet-client>=0.7.7`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` install`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` tenet-langchain`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`tenetjudgemiddleware`,children:`TenetJudgeMiddleware`}),`\n`,_jsxs(_components.p,{children:[`The primary integration — policy-first middleware for `,_jsx(_components.code,{children:`create_agent`}),`. Usage, options, and recipes live in the `,_jsx(_components.a,{href:`/guides/langchain`,children:`LangChain guide`}),`; the full constructor:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`20`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`TenetJudgeMiddleware(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client: TenetCloudJudgeClient,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` policy: JudgePolicy `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# defaults: fail-closed`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_pre: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_post: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_user_messages: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# gate agent_input`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge_tools_pre: Iterable[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# None = all tools`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge_tools_post: Iterable[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cache_verdicts: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` turn_approval: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# verdict-first SSE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` send_history: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# prior user turns`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session_id: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` |`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# auto: checkpointer thread_id`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` resolution_detection: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` resolution_detection_excluded_tools: Iterable[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` retry_nudge_max_consecutive: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`int`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` read_tools: Iterable[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# declare read tools`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` intent_resolver: Callable[[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` |`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Implements `,_jsx(_components.code,{children:`before_agent`}),` / `,_jsx(_components.code,{children:`abefore_agent`}),` (per-invocation trace setup) and `,_jsx(_components.code,{children:`wrap_tool_call`}),` / `,_jsx(_components.code,{children:`awrap_tool_call`}),` (the tool-boundary gate). Sync and async agent runs both work.`]}),`\n`,_jsx(Heading,{level:`2`,id:`read-intent`,children:`Read intent`}),`\n`,_jsxs(_components.p,{children:[`The service reads a top-level `,_jsx(_components.a,{href:`/concepts/read-intent`,children:_jsx(_components.code,{children:`intent`})}),` field on the `,_jsx(_components.code,{children:`/decide`}),` body as its `,_jsx(_components.strong,{children:`highest-precedence`}),` intent signal and records the classification on the decision trace. The current judge doesn’t change verdicts on it, so declaring reads doesn’t fast-pass anything today — it puts your read/write taxonomy on every trace, scoped by the `,_jsx(_components.code,{children:`tool_post`}),`-only rule below. Declaring which tools are reads lets the middleware assert `,_jsx(_components.code,{children:`intent=\"read\"`}),` on exactly those calls.`]}),`\n`,_jsxs(_components.p,{children:[`Declare the read taxonomy `,_jsx(_components.strong,{children:`once`}),` at construction. Either enumerate the read tools, or supply a resolver for a computed taxonomy:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`policy,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` judge_tools_pre`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"schedule_interview\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"send_phone_screen\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# mutating → pre`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` judge_tools_post`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"list_candidates\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"get_application\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# reads → post`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` read_tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"list_candidates\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"get_application\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# ← stamps intent=\"read\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # or, for a computed taxonomy (wins over read_tools):`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # intent_resolver=lambda tool_name: \"read\" if tool_name.startswith(\"get_\") else None,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`intent`}),` wire field takes `,_jsx(_components.code,{children:`read`}),` | `,_jsx(_components.code,{children:`action`}),` | `,_jsx(_components.code,{children:`unknown`}),` (default `,_jsx(_components.em,{children:`unset`}),` == `,_jsx(_components.code,{children:`unknown`}),`, omitted from the body). `,_jsx(_components.code,{children:`read`}),` / `,_jsx(_components.code,{children:`action`}),` are emitted; `,_jsx(_components.code,{children:`unknown`}),` / `,_jsx(_components.code,{children:`None`}),` are omitted so the envelope is byte-identical to not sending the field. An `,_jsx(_components.code,{children:`intent_resolver`}),` must return one of those strings or `,_jsx(_components.code,{children:`None`}),`; an out-of-vocab value raises `,_jsx(_components.code,{children:`ValueError`}),`.`]}),`\n`,_jsxs(Heading,{level:`3`,id:`safety-contract-—-tool_post-only-enforced-in-code`,children:[`Safety contract — `,_jsx(_components.code,{children:`tool_post`}),`-only, enforced in code`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`A caller-asserted `,_jsx(_components.code,{children:`intent=\"read\"`}),` is stamped `,_jsxs(_components.strong,{children:[`only at `,_jsx(_components.code,{children:`phase == \"tool_post\"`})]}),` for a tool in `,_jsx(_components.code,{children:`read_tools`}),` (or one the resolver classifies as `,_jsx(_components.code,{children:`read`}),`). It is `,_jsx(_components.strong,{children:`never`}),` emitted at `,_jsx(_components.code,{children:`agent_input`}),` or `,_jsx(_components.code,{children:`tool_pre`}),` — even when the tool name is in `,_jsx(_components.code,{children:`read_tools`}),`.`]})}),`\n`,_jsxs(_components.p,{children:[`The middleware applies the phase gate `,_jsx(_components.strong,{children:`before`}),` it consults `,_jsx(_components.code,{children:`read_tools`}),` / `,_jsx(_components.code,{children:`intent_resolver`}),`. It stamps `,_jsx(_components.code,{children:`intent=\"read\"`}),` only at `,_jsx(_components.code,{children:`tool_post`}),`; the field is never sent at `,_jsx(_components.code,{children:`agent_input`}),` or `,_jsx(_components.code,{children:`tool_pre`}),`, whatever `,_jsx(_components.code,{children:`read_tools`}),` contains.`]}),`\n`,_jsxs(_components.p,{children:[`Full field semantics and the wire header: `,_jsx(_components.a,{href:`/concepts/read-intent`,children:`Read-intent contract`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`Every call the middleware makes is judged under the `,_jsx(_components.strong,{children:`client’s`}),` `,_jsx(_components.a,{href:`/concepts/surfaces`,children:_jsx(_components.code,{children:`surface`})}),` — there is no per-tool surface option. For agents whose tools span recruiting-action kinds, scope one middleware per action family via `,_jsx(_components.code,{children:`judge_tools_pre`}),` / `,_jsx(_components.code,{children:`judge_tools_post`}),` (one client per surface), or gate mixed tools with `,_jsx(_components.code,{children:`tenet_client`}),`’s `,_jsx(_components.code,{children:`evaluate(surface=...)`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`An `,_jsx(_components.code,{children:`include_with_caveats`}),` verdict rides through as a `,_jsx(_components.strong,{children:`non-blocking allow`}),`: the judge’s advisory note is folded onto `,_jsx(_components.code,{children:`ctx.metadata`}),` and annotated onto the proceeding tool result’s `,_jsx(_components.code,{children:`response_metadata`}),` (status preserved, never an error). It never reaches `,_jsx(_components.code,{children:`on_review`}),` and never interrupts. On streaming runs (`,_jsx(_components.code,{children:`stream=True`}),`), severity-routed dispatch waits for the final severity, not the provisional verdict event — see `,_jsx(_components.a,{href:`/guides/streaming#provisional-verdicts`,children:`Verdict-first streaming`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`tell-the-judge-what-the-tool-does`,children:`Tell the judge what the tool does`}),`\n`,_jsx(_components.p,{children:`The judge sees a tool call as its arguments and little else, so it can misread a call whose meaning sits in the user’s words or in the tool’s purpose. The request-shaping options add those facts without subclassing the client.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`14`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` JudgeCall, RequestShape, TenetJudgeMiddleware`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` shaper`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`call`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: JudgeCall) -> RequestShape `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Runs for every judged call, including agent_input; non-None fields win.`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` RequestShape(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`context`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: current_page.job_title})`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`policy,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` surface_for_tool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"rank_candidates\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"resume_triage_rank\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# per-call surface`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tool_descriptions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"rank_candidates\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Ranks applicants for the open role.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` send_user_prompt_on_tool_phases`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# the user's own words, not a dump of the args`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` request_shaper`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`shaper,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`surface_for_tool`}),`: the `,_jsx(_components.code,{children:`surface`}),` for a listed tool at `,_jsx(_components.code,{children:`tool_pre`}),` / `,_jsx(_components.code,{children:`tool_post`}),`;\nother tools use the client’s surface.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`tool_descriptions`}),`: sent as `,_jsx(_components.code,{children:`context[\"tool_description\"]`}),` for a listed tool.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`send_user_prompt_on_tool_phases`}),`: the latest user message goes out as\n`,_jsx(_components.code,{children:`user_prompt=`}),` (the judge’s `,_jsx(_components.code,{children:`recruiter_prompt`}),`) on tool phases, unless the tool’s\nown arguments already carry a `,_jsx(_components.code,{children:`recruiter_prompt`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`request_shaper`}),`: gets a `,_jsx(_components.code,{children:`JudgeCall`}),` (phase, tool name, input, output, latest user\nmessage, graph state, runtime) and returns a `,_jsx(_components.code,{children:`RequestShape`}),` (`,_jsx(_components.code,{children:`surface`}),`, `,_jsx(_components.code,{children:`context`}),`,\n`,_jsx(_components.code,{children:`user_prompt`}),`, `,_jsx(_components.code,{children:`candidate_content`}),`) or `,_jsx(_components.code,{children:`None`}),`. `,_jsx(_components.code,{children:`context`}),` is merged over the default\ncontext; `,_jsx(_components.code,{children:`candidate_content=`}),` is how the output of a tool is judged as candidate\ntext. A shaper that raises propagates, so a bug is never silently sent unshaped.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Reserved context keys (`,_jsx(_components.code,{children:`tool_name`}),`, `,_jsx(_components.code,{children:`recruiter_prompt`}),`, …) are still rejected by the\nclient with `,_jsx(_components.code,{children:`ValueError`}),`; use `,_jsx(_components.code,{children:`user_prompt`}),` / `,_jsx(_components.code,{children:`candidate_content`}),` for those. The\nverdict cache key includes whatever was shaped. If you also call the client directly,\n`,_jsx(_components.code,{children:`default_judge_context(tool_name, tool_input)`}),` returns the same default `,_jsx(_components.code,{children:`context`}),` the\nmiddleware builds for that call, and `,_jsx(_components.code,{children:`RESERVED_CONTEXT_KEYS`}),` lists the names to keep out.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`max_tool_output_chars`}),` (default `,_jsx(_components.code,{children:`None`}),`, no cap) cuts the tool output sent to the\njudge at `,_jsx(_components.code,{children:`tool_post`}),` to that many characters, because large outputs drive judge\nlatency. The cut applies to the judge’s copy only: the `,_jsx(_components.code,{children:`tool_output`}),` a\n`,_jsx(_components.code,{children:`request_shaper`}),` sees and the verdict cache key use the cut text, while the tool’s\nreal result returned to the agent and the `,_jsx(_components.code,{children:`JudgeContext.tool_output`}),` your policy\ncallbacks receive stay whole. Must be `,_jsx(_components.code,{children:`>= 1`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`send_user_prompt_on_tool_phases`}),` is silently a no-op for a call whose arguments\nalready carry `,_jsx(_components.code,{children:`recruiter_prompt`}),`: the judge reads the arguments’ own ask.`]}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`These options change what the judge reads, so they can change verdicts. Turn them on in a test environment and compare before production.`})}),`\n`,_jsx(Heading,{level:`2`,id:`record-every-decision`,children:`Record every decision`}),`\n`,_jsxs(_components.p,{children:[`You can’t tune a policy you can’t see. `,_jsx(_components.code,{children:`on_decision`}),` hands you one record per judged call.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`on_decision`}),` takes a sink, or a list of sinks, and gets one `,_jsx(_components.code,{children:`DecisionRecord`}),` per\njudged call after the policy has chosen an action. `,_jsx(_components.code,{children:`outcome`}),` is that action’s kind\n(`,_jsx(_components.code,{children:`allow`}),`, `,_jsx(_components.code,{children:`block`}),`, `,_jsx(_components.code,{children:`tool_error`}),`, `,_jsx(_components.code,{children:`retry_nudge`}),`, …), `,_jsx(_components.code,{children:`turn_approved`}),` when turn\napproval passed the call, `,_jsx(_components.code,{children:`interrupted`}),` when a review callback paused the run, or `,_jsx(_components.code,{children:`policy_error`}),` (with\n`,_jsx(_components.code,{children:`extra={\"error\": \"\u003cExceptionName>\"}`}),`) when a policy callback raised any other\nexception; that exception is then re-raised unchanged. A cache hit carries `,_jsx(_components.code,{children:`extra={\"cached\": True}`}),`; with the judge unavailable\n`,_jsx(_components.code,{children:`decision`}),` is `,_jsx(_components.code,{children:`\"unavailable\"`}),` and `,_jsx(_components.code,{children:`outcome`}),` is what the policy did. A failing sink\nis logged and never affects the run.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`17`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`17`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` logging`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_client.observability `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langfuse_score_sink, logging_sink`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` opentelemetry `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` trace`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` app_trace_id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` |`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ctx `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` trace.get_current_span().get_span_context()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` format`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ctx.trace_id, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"032x\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ctx.is_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`policy,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` on_decision`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` logging_sink(logging.getLogger(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"tenet\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langfuse_score_sink(langfuse),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` trace_id_provider`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`app_trace_id,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`trace_id_provider`}),` returns the run’s trace id (32 hex characters), so\n`,_jsx(_components.code,{children:`record.trace_id`}),` is your own trace and `,_jsx(_components.code,{children:`langfuse_score_sink`}),` scores it. `,_jsx(_components.code,{children:`None`}),` or an\ninvalid value falls back to a generated id. Trace ids do not reach Tenet; they live\non the client call, `,_jsx(_components.code,{children:`JudgeContext`}),` and the record.`]}),`\n`,_jsxs(_components.p,{children:[`A human-review pause writes an `,_jsx(_components.code,{children:`interrupted`}),` record, and the resumed pass writes\nanother (marked `,_jsx(_components.code,{children:`cached`}),` when `,_jsx(_components.code,{children:`cache_verdicts`}),` is on), so a paused review yields two.`]}),`\n`,_jsx(Heading,{level:`2`,id:`try-it-before-you-enforce-it`,children:`Try it before you enforce it`}),`\n`,_jsx(_components.p,{children:`“What would the judge do to my traffic?” should not need enforcement to answer. Shadow mode judges every phase without acting on it.`}),`\n`,_jsxs(_components.p,{children:[`“What would the judge do to my traffic?” should not need enforcement to answer.\nWith `,_jsx(_components.code,{children:`mode=\"shadow\"`}),` every phase the middleware would judge is judged without\nacting: the policy is never dispatched, the hooks return as if the call were\nallowed, and each check ends in one `,_jsx(_components.code,{children:`DecisionRecord`}),` with `,_jsx(_components.code,{children:`mode=\"shadow\"`}),` and\n`,_jsx(_components.code,{children:`outcome`}),` set to the verdict (`,_jsx(_components.code,{children:`allow`}),`, `,_jsx(_components.code,{children:`caveat`}),`, `,_jsx(_components.code,{children:`review`}),`, `,_jsx(_components.code,{children:`block`}),`, `,_jsx(_components.code,{children:`degraded`}),`,\n`,_jsx(_components.code,{children:`unavailable`}),`, or `,_jsx(_components.code,{children:`skipped`}),`). Nothing is cached, approved or written to review\nstate.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` logging`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_client.observability `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` logging_sink`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` mode`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"shadow\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` check_user_messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` on_decision`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`logging_sink(logging.getLogger(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"tenet\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`model, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tools, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`middleware`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw.middlewares())`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Async hooks (`,_jsx(_components.code,{children:`ainvoke`}),` / `,_jsx(_components.code,{children:`astream`}),`) judge in a background task and never wait for\nthe answer. Sync hooks judge inline under `,_jsx(_components.code,{children:`shadow_timeout_s`}),` (default 15 seconds),\nwhich adds that latency to the turn, so prefer async. A judge that fails or misses\nthe deadline is recorded as `,_jsx(_components.code,{children:`unavailable`}),`; a shadow check never raises into the turn.\n`,_jsx(_components.code,{children:`stream=True`}),` is ignored in shadow mode. `,_jsx(_components.code,{children:`shadow_timeout_s`}),` must be a finite number above\nzero. If your `,_jsx(_components.code,{children:`is_user_message`}),` raises in shadow mode, the error is logged and that check is\nskipped. `,_jsx(_components.code,{children:`with_human_review(..., mode=\"shadow\")`}),` raises `,_jsx(_components.code,{children:`ValueError`}),`: it would build a review\nrecipe that never reviews.`]}),`\n`,_jsxs(_components.p,{children:[`A consumer of the records should filter on `,_jsx(_components.code,{children:`outcome`}),`: a skipped check is recorded with\n`,_jsx(_components.code,{children:`decision=\"unavailable\"`}),` like a judge outage, and only `,_jsx(_components.code,{children:`outcome`}),` tells them apart.`]}),`\n`,_jsxs(_components.p,{children:[`Shadow checks share the judge’s capacity with checks that block, and a burst of them\nonce tripped the engine’s circuit breaker. A `,_jsx(_components.code,{children:`ShadowRunner`}),` therefore allows only\n`,_jsx(_components.code,{children:`max_in_flight=2`}),` checks at a time and skips the rest (recorded with\n`,_jsx(_components.code,{children:`outcome=\"skipped\"`}),`, `,_jsx(_components.code,{children:`extra={\"reason\": \"in_flight_limit\"}`}),`); a skipped check is\nnever queued. The default runner is one per process, so apps that build the\nmiddleware per request share a single cap. Pass `,_jsx(_components.code,{children:`shadow_runner=ShadowRunner(...)`}),`\nto use your own, and call `,_jsx(_components.code,{children:`await default_shadow_runner().drain()`}),` at application\nshutdown so checks in flight finish.`]}),`\n`,_jsxs(_components.p,{children:[`Shadow checks never open or close the client’s circuit breaker (they are sent with\n`,_jsx(_components.code,{children:`record_breaker=False`}),`), so a fault only the shadow checks see cannot fail a real turn,\nand their successes do not reset the enforcing checks’ failure count. They are skipped,\nwith no network call, while the breaker is open.`]}),`\n`,_jsxs(_components.p,{children:[`The cap applies to the async hooks only: sync shadow hooks run inline and are not capped.\nThe records of checks still in flight are lost if the event loop closes without a\n`,_jsx(_components.code,{children:`drain()`}),` (a script that ends right after `,_jsx(_components.code,{children:`asyncio.run(...)`}),` sees none), and `,_jsx(_components.code,{children:`drain()`}),`\nwaits only for the checks of the loop that calls it.`]}),`\n`,_jsxs(_components.p,{children:[`To record a verdict on the agent’s final reply (`,_jsx(_components.code,{children:`phase=\"agent_output\"`}),`), add the\nreply check:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`model,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tools,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` middleware`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw.middlewares(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`check_agent_output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"shadow\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`middlewares()`}),` returns `,_jsx(_components.code,{children:`[mw, RefusedExchangeFilter?, AgentOutputCheck(...)]`}),` (the\nfilter only when `,_jsx(_components.code,{children:`refusal_marker`}),` is set), sharing the sinks, request shaper and\nrunner. The check’s middleware name derives from the parent’s `,_jsx(_components.code,{children:`name=`}),`, so two named\njudges can share one agent. `,_jsx(_components.code,{children:`AgentOutputCheck`}),` is a separate class so users who do not turn\nit on pay no extra graph node per model call. It checks only a model message with\ntext and no tool calls (not the canned text of a block), sends it as `,_jsx(_components.code,{children:`agent_reply=`}),`\nwith the user’s latest message as `,_jsx(_components.code,{children:`user_prompt=`}),`, and only observes: `,_jsx(_components.code,{children:`mode=\"enforce\"`}),`\nis not supported, since holding or retracting a streamed reply is a product decision\nfor your app. A `,_jsx(_components.code,{children:`request_shaper`}),` receives a `,_jsx(_components.code,{children:`JudgeCall`}),` with `,_jsx(_components.code,{children:`phase=\"agent_output\"`}),`,\nthe reply as `,_jsx(_components.code,{children:`tool_input`}),`, and the user’s ask as `,_jsx(_components.code,{children:`user_message`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`make-sure-every-tool-is-classified`,children:`Make sure every tool is classified`}),`\n`,_jsxs(_components.p,{children:[`A tool added later and listed nowhere would run with no check and no warning. `,_jsx(_components.code,{children:`strict_tools`}),` turns that into a deploy-time error.`]}),`\n`,_jsxs(_components.p,{children:[`The middleware judges by tool name, so with `,_jsx(_components.code,{children:`judge_tools_pre`}),` / `,_jsx(_components.code,{children:`judge_tools_post`}),` set, a\ntool added later and listed nowhere runs with no check and no warning. Classify every tool:\njudged (`,_jsx(_components.code,{children:`judge_tools_pre`}),`, `,_jsx(_components.code,{children:`judge_tools_post`}),`), a read (`,_jsx(_components.code,{children:`read_tools`}),`), or deliberately not\njudged (`,_jsx(_components.code,{children:`unjudged_tools`}),`, a mapping from tool name to the reason, or just names). Leaving a\nphase list unset (`,_jsx(_components.code,{children:`None`}),`) means every tool is judged at that phase, so name both lists.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` judge_tools_pre`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"send_email\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` judge_tools_post`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"send_email\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` read_tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"search_candidates\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` unjudged_tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"move_stage\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ids and a stage name only; the ask behind it is judged\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` strict_tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`With `,_jsx(_components.code,{children:`strict_tools=True`}),`, a call to a tool that no enabled phase judges, and that is neither in\n`,_jsx(_components.code,{children:`read_tools`}),` nor in `,_jsx(_components.code,{children:`unjudged_tools`}),`, does not run: the tool wrapper raises\n`,_jsx(_components.code,{children:`UnclassifiedToolError`}),` naming the tool. “Judged” is what the wrapper itself decides: the\nphase’s `,_jsx(_components.code,{children:`check_pre`}),` / `,_jsx(_components.code,{children:`check_post`}),` is on and its list is unset (every tool) or names the tool.\nA disabled phase covers nothing, and an unset list covers every tool only at an enabled phase.\nSo with `,_jsx(_components.code,{children:`judge_tools_pre=[\"a\"]`}),`, the post list unset and `,_jsx(_components.code,{children:`check_post`}),` on, an unlisted tool is\njudged at post and runs; with `,_jsx(_components.code,{children:`check_post=False`}),` it raises. It applies in `,_jsx(_components.code,{children:`mode=\"shadow\"`}),` too,\nsince the point is to find the tool before you enforce. A tool both judged and in\n`,_jsx(_components.code,{children:`unjudged_tools`}),` raises `,_jsx(_components.code,{children:`ValueError`}),` at construction.`]}),`\n`,_jsxs(_components.p,{children:[`The error is a deploy-time guard, not a recovery path. Raised in the middle of a turn it leaves\nthe thread with an assistant tool call that has no result (the tool did not run), which a\nprovider rejects on the next turn. Use `,_jsx(_components.code,{children:`assert_tools_classified`}),` in a test so it fires before\nproduction.`]}),`\n`,_jsx(_components.p,{children:`Catch it in CI rather than in production, with one line in your test suite:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` test_every_tool_is_classified`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` mw.assert_tools_classified(all_tools)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`It raises `,_jsx(_components.code,{children:`UnclassifiedToolError`}),` listing every unclassified tool, and every name in a list\nthat no tool carries (a stale entry after a rename). `,_jsx(_components.code,{children:`mw.tool_classification(all_tools)`}),`\nreturns the label per tool: `,_jsx(_components.code,{children:`pre`}),`, `,_jsx(_components.code,{children:`post`}),`, `,_jsx(_components.code,{children:`pre+post`}),` (enabled phases only), `,_jsx(_components.code,{children:`read`}),`, `,_jsx(_components.code,{children:`unjudged`}),` or\n`,_jsx(_components.code,{children:`unclassified`}),`. Both accept anything `,_jsx(_components.code,{children:`create_agent`}),` does as a tool: a `,_jsx(_components.code,{children:`BaseTool`}),`, a plain\nfunction, a provider dict tool (skipped when it has no `,_jsx(_components.code,{children:`name`}),`) or a name.`]}),`\n`,_jsx(Heading,{level:`2`,id:`recursion-limit`,children:`Recursion limit`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`create_agent`}),` turns each node hook a middleware overrides into a graph node, and each node\nrun uses one LangGraph recursion step. `,_jsx(_components.code,{children:`TenetJudgeMiddleware`}),` costs one step per run\n(`,_jsx(_components.code,{children:`before_agent`}),`) plus one per model call (`,_jsx(_components.code,{children:`before_model`}),`), whether or not\n`,_jsx(_components.code,{children:`check_user_messages`}),` is on; tool judging costs none. `,_jsx(_components.code,{children:`AgentOutputCheck`}),` costs one more per\nmodel call. `,_jsx(_components.code,{children:`RefusedExchangeFilter`}),` costs none (`,_jsx(_components.code,{children:`recursion_steps`}),` returns 0), and\n`,_jsx(_components.code,{children:`judge_unanswered_messages`}),` adds none: it is the same node judging more messages. A turn\nnear your `,_jsx(_components.code,{children:`recursion_limit`}),` can fail with `,_jsx(_components.code,{children:`GraphRecursionError`}),` unless you add the cost:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`max_model_calls `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 16`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`middleware `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` mw.middlewares(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`check_agent_output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"shadow\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`limit `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 50`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` sum`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(m.recursion_steps(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`model_calls`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`max_model_calls) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` m `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` middleware)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent.invoke(inputs, {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"recursion_limit\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: limit})`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`human-review`,children:`Human review`}),`\n`,_jsxs(_components.p,{children:[`A `,_jsx(_components.code,{children:`review`}),` or `,_jsx(_components.code,{children:`block`}),` verdict can pause the agent for a person and resume from the answer, which needs a checkpointer and a stable `,_jsx(_components.code,{children:`thread_id`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`27`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`27`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langchain.agents `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langgraph.checkpoint.memory `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` InMemorySaver`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langgraph.types `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Command`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetCloudJudgeClient`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` APPROVE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, TenetJudgeMiddleware, interrupt_policy`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`judge `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware.with_human_review(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetCloudJudgeClient.from_env(),`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`interrupt_policy(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`strict_approve`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`), `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# only an explicit approve approves a message`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-sonnet-4-5-20250514\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[send_claim_to_payer],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` middleware`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`judge.middlewares(),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` checkpointer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`InMemorySaver(),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`config `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"configurable\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"thread_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"case-123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}}`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.invoke({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Submit the packet.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}]}, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`config`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`config, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`version`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"v2\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result.interrupts:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` prompt `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result.interrupts[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].value `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# show prompt[\"display_message\"] and prompt[\"choices\"]`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.invoke(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Command(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`resume`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`**`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`APPROVE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"review_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: prompt[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"review_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]}),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` config`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`config,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` version`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"v2\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The prompt is `,_jsx(_components.code,{children:`format_review_event(...).to_dict()`}),` plus `,_jsx(_components.code,{children:`phase`}),`, `,_jsx(_components.code,{children:`review_id`}),` and, for a message,\n`,_jsx(_components.code,{children:`user_message`}),`. Ways to answer:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{\"action\": \"approve\", \"review_id\": ...}`}),` approves (`,_jsx(_components.code,{children:`APPROVE`}),` is the first part).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{\"selection\": \"\u003ctext>\"}`}),` at a message replaces it with that text, which is judged in turn. It is\nnot an approval and leaves no approval behind. Anything else at a tool asks again.`]}),`\n`,_jsx(_components.li,{children:`A block can only be dismissed; no answer lets it through.`}),`\n`,_jsxs(_components.li,{children:[`A message the judge reports as an attack on the agent (a `,_jsx(_components.code,{children:`SAFETY-`}),` label) gets no prompt: the turn\nends with `,_jsx(_components.code,{children:`DEFAULT_REFUSAL_MESSAGE`}),`, and that exchange is hidden from later judge calls and the\nmodel. Set `,_jsx(_components.code,{children:`refuse_label_prefixes=()`}),` to turn that off.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Echo `,_jsx(_components.code,{children:`review_id`}),`. Without it, a resume that lands where the judge reports a different finding for\nthe same call approves the one the person never saw. A client that does not echo it still works.\nAt a message, any non-approve answer approves by default (what existing clients rely on); the recipe\nabove passes `,_jsx(_components.code,{children:`interrupt_policy(strict_approve=True)`}),`, which you should do in a new integration so\nonly `,_jsx(_components.code,{children:`approve`}),` does. `,_jsx(_components.code,{children:`review_id`}),` binds an answer to the kind of finding (phase, tool name, labels), not to the message\ntext or the tool arguments. Keep tools idempotent: LangGraph re-runs the node that paused, from the top, on resume.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`with_human_review`}),` sets `,_jsx(_components.code,{children:`check_user_messages`}),`, `,_jsx(_components.code,{children:`cache_verdicts`}),`, `,_jsx(_components.code,{children:`turn_approval`}),`,\n`,_jsx(_components.code,{children:`persist_review_state`}),`, `,_jsx(_components.code,{children:`rejudge_overridden_input`}),`, `,_jsx(_components.code,{children:`judge_unanswered_messages`}),` (a flagged message\nwhose pause the app abandons by sending a new message cannot reach the model unapproved) and\n`,_jsx(_components.code,{children:`refusal_marker=DEFAULT_REFUSAL_MESSAGE`}),`; every one can be overridden by keyword. To change the\nrefusal text, pass `,_jsx(_components.code,{children:`with_human_review(..., refusal_message=\"...\")`}),`: the one string goes to both\nthe policy and `,_jsx(_components.code,{children:`refusal_marker`}),`. If you pass your own `,_jsx(_components.code,{children:`policy=`}),` built with `,_jsx(_components.code,{children:`interrupt_policy(...)`}),`\n(`,_jsx(_components.code,{children:`display=`}),`, `,_jsx(_components.code,{children:`payload=`}),`, `,_jsx(_components.code,{children:`accept_rewrite=`}),`, `,_jsx(_components.code,{children:`refusal_message=`}),`, `,_jsx(_components.code,{children:`block_message=`}),`, `,_jsx(_components.code,{children:`on_action=`}),`,\nplus any `,_jsx(_components.code,{children:`JudgePolicy`}),` option) and also a `,_jsx(_components.code,{children:`refusal_marker`}),`, you own keeping the two the same.\n`,_jsx(_components.code,{children:`on_action(name, ctx, verdict)`}),` hears `,_jsx(_components.code,{children:`paused`}),`, `,_jsx(_components.code,{children:`approved`}),`, `,_jsx(_components.code,{children:`rewritten`}),`, `,_jsx(_components.code,{children:`blocked`}),`, `,_jsx(_components.code,{children:`refused`}),` and\n`,_jsx(_components.code,{children:`replayed_answer_skipped`}),`; `,_jsx(_components.code,{children:`approved`}),` and `,_jsx(_components.code,{children:`rewritten`}),` are reported once per decision (a second message approved, or one\nmessage rewritten twice, reports again) even though LangGraph re-runs the node that paused, from\nthe top, on resume. A review that gets no usable answer 25 times in a row raises `,_jsx(_components.code,{children:`RuntimeError`}),`. Keep tools idempotent for the same\nreason.`]}),`\n`,_jsx(Heading,{level:`2`,id:`reviews-that-survive-a-restart`,children:`Reviews that survive a restart`}),`\n`,_jsxs(_components.p,{children:[`By default the middleware remembers “this message was judged” and “the user\napproved this finding for this turn” in memory on the instance. Turn on\n`,_jsx(_components.code,{children:`persist_review_state=True`}),` when you run with a checkpointer and more than one\nprocess, or rebuild the agent for every request: a resume that lands on a new\ninstance would otherwise judge the approved message again, and a tool that\nraises the same finding would pause the user a second time.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`mw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`policy,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` check_user_messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` turn_approval`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` send_history`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` persist_review_state`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Four private graph-state channels hold the state; they never reach the caller’s output. Messages without an id are judged every time. Two middleware instances that should not share state need different `,_jsx(_components.code,{children:`review_state_prefix`}),` and `,_jsx(_components.code,{children:`name=`}),` values.`]}),`\n`,_jsxs(_components.p,{children:[`The default policy (no `,_jsx(_components.code,{children:`on_review`}),`) allows a `,_jsx(_components.code,{children:`review`}),`, so with persisted state that\nallow is recorded as a reviewed id and a turn approval, with no human involved:\nthe message is then left out of later history. Pass an `,_jsx(_components.code,{children:`on_review`}),` that pauses if\nthat is not what you want.`]}),`\n`,_jsx(Heading,{level:`3`,id:`rewrites-and-refusals`,children:`Rewrites and refusals`}),`\n`,_jsx(_components.p,{children:`Two options for a human-review flow, whatever policy drives it.`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`rejudge_overridden_input=True`}),`. When the policy answers `,_jsx(_components.code,{children:`override_input`}),` at the\nmodel boundary (for example the user picked a suggested rewrite), the default is\nto swap in the new text and go straight to the model: the new text is never\njudged, and the replacement drops the original message’s id and kwargs, so the\nthread no longer shows which message was replaced. With the option on, the\nreplacement keeps the original’s `,_jsx(_components.code,{children:`id`}),` and `,_jsx(_components.code,{children:`additional_kwargs`}),` (plus\n`,_jsx(_components.code,{children:`additional_kwargs[\"tenet_rewrite\"] = True`}),`) and is judged as the new\n`,_jsx(_components.code,{children:`agent_input`}),` before the model runs, again through your policy. A rewrite may be\noverridden again; after three replacements the next `,_jsx(_components.code,{children:`override_input`}),` ends the turn\nwith “The rewritten message could not be approved.” An `,_jsx(_components.code,{children:`override_input`}),` never\nrecords a turn approval, and with `,_jsx(_components.code,{children:`persist_review_state`}),` the message id is\nrecorded as allowed only after the final allow. The replacement must itself be\nthe message that is judged: if `,_jsx(_components.code,{children:`is_user_message`}),` would not accept the replacement\ntext, the turn ends with the same “could not be approved” message instead of\njudging some other message.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`judge_unanswered_messages=True`}),` (needs `,_jsx(_components.code,{children:`persist_review_state=True`}),`). A flagged\nmessage pauses the graph. If the app then sends a new message on the same thread\ninstead of resuming, the default is to judge only the latest message, and the\nmodel receives the flagged one as history without an approval ever given. With the\noption on, every user message after the last assistant message (per\n`,_jsx(_components.code,{children:`is_user_message`}),`, refused exchanges excluded) that is not already recorded as\nallowed is judged, oldest first, as `,_jsx(_components.code,{children:`agent_input`}),`. The first whose action is not\nan allow decides the turn, and a pause is about that message; the model runs only\nwhen all are allowed. A rewrite replaces whichever message was being judged. The block, refusal and\ncap messages the middleware writes carry `,_jsx(_components.code,{children:`additional_kwargs[\"tenet_answers\"]`}),` (the\nid of the message they answer), so a message that sat before such a reply is still\njudged on the next turn, and one the reply already answers is not judged again. The\ntag is written only when `,_jsx(_components.code,{children:`judge_unanswered_messages`}),` is on or a `,_jsx(_components.code,{children:`refusal_marker`}),` is\nset; with neither, the stored messages are what earlier releases wrote.`]}),`\n`,_jsxs(_components.p,{children:[`The option covers the messages after the last model reply. An in-place edit of a\nmessage that was already answered (same id, new text, before the last reply) is not\nre-judged, the same as without the option. Cost is one judge call per unanswered\nmessage, so a thread restored with many unanswered messages is judged that many times\non its first turn. When several flagged messages are queued, each resume re-judges the\nearlier ones (the node’s record of them is lost at every pause) unless the verdict\ncache is on (`,_jsx(_components.code,{children:`cache_verdicts`}),`).`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`refusal_marker=\"...\"`}),`. When a message is an attack on the agent and the turn ends\nwith a fixed refusal, that exchange would otherwise stay in the conversation: with\n`,_jsx(_components.code,{children:`send_history`}),` the judge flags every later message with the old turn as evidence,\nand the refused instruction reaches the model on the next allowed turn. Set the\nmarker to the exact refusal text (`,_jsx(_components.code,{children:`DEFAULT_REFUSAL_MESSAGE`}),` is a ready one) and\nreturn it from your block action. An `,_jsx(_components.code,{children:`AIMessage`}),` equal to the marker, with the\nuser message it refused, is a refused exchange (the message named by its\n`,_jsx(_components.code,{children:`tenet_answers`}),` tag, or, for a reply with no tag, the user message right before it): it is left out of the history\nsent to the judge, is never “the latest user message”, and is removed from every\nmodel request. The checkpoint keeps it, so the transcript still shows it. The\nmarker is matched against stored transcripts: never reword it once it is in\nproduction, or old refusals come back into the conversation.`]}),`\n`,_jsxs(_components.p,{children:[`The policy-authored refusal (a block or tool-error message equal to the marker, and\nthe “could not be approved” message after a rewrite cap) is also tagged\n`,_jsx(_components.code,{children:`additional_kwargs[\"tenet_refusal\"] = True`}),`. An exchange counts as refused when its\nreply carries the tag or equals the marker exactly, so threads stored before this\noption, which have only the text, still match. A model reply that happens to equal\nthe marker hides the user message before it too; that is known and low\nconsequence.`]}),`\n`,_jsxs(_components.p,{children:[`The model request is cleaned by a separate middleware, `,_jsx(_components.code,{children:`RefusedExchangeFilter`}),`.\nHand `,_jsx(_components.code,{children:`create_agent`}),` `,_jsx(_components.code,{children:`mw.middlewares()`}),` rather than `,_jsx(_components.code,{children:`[mw]`}),`: it returns `,_jsx(_components.code,{children:`[mw]`}),` when\nno marker is set, and `,_jsx(_components.code,{children:`[mw, RefusedExchangeFilter(mw)]`}),` when one is. The filter adds\na model-call wrapper (an edge and a trace span per model call) only when you opt in;\nits name derives from the judge’s `,_jsx(_components.code,{children:`name=`}),`, so two named judges can share an agent.\nWith a marker set and only `,_jsx(_components.code,{children:`[mw]`}),` passed, the first model call raises a\n`,_jsx(_components.code,{children:`RuntimeError`}),` rather than letting refused text reach the model silently. The\nfilter changes the model request only: the checkpoint still holds the refused\nexchange, so other middleware that reads state (a summarizer, say) still sees it.\nIf every message left is a refused exchange, the turn ends without calling the\nmodel.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` DEFAULT_REFUSAL_MESSAGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, TenetJudgeMiddleware`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`middleware `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TenetJudgeMiddleware(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` judge,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` policy`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`JudgePolicy(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` on_block`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`lambda`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ctx`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`v`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: JudgeAction.tool_error(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`DEFAULT_REFUSAL_MESSAGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` check_user_messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` send_history`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` rejudge_overridden_input`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` refusal_marker`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`DEFAULT_REFUSAL_MESSAGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# create_agent(model=model, tools=tools, middleware=middleware.middlewares())`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`per-thread-state`,children:`Per-thread state`}),`\n`,_jsxs(_components.p,{children:[`When a thread id is configured (a checkpointer plus\n`,_jsx(_components.code,{children:`{\"configurable\": {\"thread_id\": ...}}`}),`), one middleware instance is safe to\nshare across concurrent conversations: trace ids, retry-nudge budgets, the\nverdict cache and turn approvals are all scoped to the thread. Without a thread\nid every run shares one scope, as a single-conversation instance does.`]}),`\n`,_jsxs(_components.p,{children:[`Per-thread state is bounded: `,_jsx(_components.code,{children:`TenetJudgeMiddleware(judge, max_threads=1024)`}),`\nkeeps the 1024 most recently used threads and evicts the least recently used\nbeyond that. Evicting a thread drops its cache, approval, trace and retry-nudge\ncounters. A thread’s trace id is constant within a run while the thread stays\namong the `,_jsx(_components.code,{children:`max_threads`}),` most recently used; an evicted thread starts a new\ntrace on its next tool call.`]}),`\n`,_jsx(Heading,{level:`2`,id:`timeouts`,children:`Timeouts`}),`\n`,_jsxs(_components.p,{children:[`A timeout reaches `,_jsx(_components.code,{children:`on_timeout`}),`; if you leave it unset, a timeout falls back to `,_jsx(_components.code,{children:`on_unavailable`}),`, so setting only `,_jsx(_components.code,{children:`on_unavailable`}),` covers both.`]}),`\n`,_jsx(Heading,{level:`2`,id:`toolguardmiddleware`,children:`ToolGuardMiddleware`}),`\n`,_jsxs(_components.p,{children:[`Constructor-injected tool `,_jsx(_components.strong,{children:`allowlist`}),` — structural defence-in-depth that stops the model from calling tools the application never registered, at the agent layer, instead of scanning model output for leaked tool names after the fact.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langchain.agents `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tenet_langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuardMiddleware`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`TOOLS`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [search_tool, send_email_tool, delete_db_tool]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`TOOL_NAMES`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` frozenset`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(t.name `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` t `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` TOOLS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# one source of truth`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`TOOLS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` middleware`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[ToolGuardMiddleware(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`allowed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`TOOL_NAMES`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` context_schema`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`RequestContext, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:\"# optional — a `scopes: frozenset[str]` field\"})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Two layers enforce independently:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`Layer 1 — `,_jsx(_components.code,{children:`wrap_model_call`}),`:`]}),` per-request scoping. Narrows the tools the model sees to the subset permitted by `,_jsx(_components.code,{children:`runtime.context.scopes`}),`. No-ops cleanly when context or `,_jsx(_components.code,{children:`scopes`}),` is absent, so Layer 2 stays the unconditional enforcement point.`]}),`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`Layer 2 — `,_jsx(_components.code,{children:`wrap_tool_call`}),`:`]}),` hard enforcement. Any call whose name is not in the constructor `,_jsx(_components.code,{children:`allowed`}),` set short-circuits with `,_jsx(_components.code,{children:`ToolMessage(status=\"error\")`}),` — the handler is never invoked, regardless of how the call surfaced. Comparison is by tool name (string), not object identity.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`The allowlist lives on the instance (constructor), never written to messages or `,_jsx(_components.code,{children:`AgentState`}),`, so it is never serialized into the prompt or captured in checkpoints/traces. Both sync and async (`,_jsx(_components.code,{children:`awrap_tool_call`}),`) are implemented. It does `,_jsx(_components.strong,{children:`not`}),` validate tool `,_jsx(_components.em,{children:`arguments`}),` (an allowed tool with poisoned args passes) — compose with argument validation or `,_jsx(_components.code,{children:`HumanInTheLoopMiddleware`}),` on high-impact tools.`]}),`\n`,_jsx(Heading,{level:`2`,id:`adjacent-classes`,children:`Adjacent classes`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Class`}),_jsx(_components.th,{children:`Status`}),_jsx(_components.th,{children:`Use when`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`TenetJudgeMiddleware`})}),_jsx(_components.td,{children:_jsx(_components.strong,{children:`Current`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`create_agent`}),` integrations — always start here`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`TenetMiddleware`})}),_jsx(_components.td,{children:`Separate product`}),_jsx(_components.td,{children:`Local Tenet server for PII detect/redact — not the cloud judge`})]}),_jsxs(_components.tr,{children:[_jsxs(_components.td,{children:[_jsx(_components.code,{children:`TenetCallbackHandler`}),` / `,_jsx(_components.code,{children:`AsyncTenetCallbackHandler`})]}),_jsx(_components.td,{children:`Adjacent`}),_jsxs(_components.td,{children:[`Non-middleware LangChain chains; hooks `,_jsx(_components.code,{children:`on_tool_start`}),` / `,_jsx(_components.code,{children:`on_tool_end`}),` against the local server`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`TenetGuard`})}),_jsx(_components.td,{children:`Adjacent`}),_jsxs(_components.td,{children:[`Standalone PII detection on arbitrary text (`,_jsx(_components.code,{children:`detect_pii`}),`)`]})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`hitl-display-helpers`,children:`HITL display helpers`}),`\n`,_jsxs(_components.p,{children:[`For harnesses that surface `,_jsx(_components.code,{children:`review`}),` verdicts to humans:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`RiskLabelDisplay`}),` + `,_jsx(_components.code,{children:`DEFAULT_EEO_TOPIC_MAPPING`}),` — render risk codes (`,_jsx(_components.code,{children:`EEO-AGE-PROXY-01`}),` → “age-discrimination”) as reviewer-friendly topics; operator-only codes map to `,_jsx(_components.code,{children:`None`}),` and drop out.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`ReviewEvent`}),` + `,_jsx(_components.code,{children:`format_review_event`}),` — a transport-ready review record with `,_jsx(_components.code,{children:`to_sse()`}),` / `,_jsx(_components.code,{children:`to_dict()`}),` renderers. The middleware never calls these; your app does, from its HITL handler.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Full usage — callbacks, SSE rendering, resume semantics — in the `,_jsx(_components.a,{href:`/guides/hitl`,children:`HITL guide`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`These pair with an `,_jsx(_components.code,{children:`interrupt()`}),`-based `,_jsx(_components.code,{children:`on_review`}),` callback (`,_jsx(_components.a,{href:`/guides/policies#human-in-the-loop`,children:`Human in the loop`}),`) and `,_jsx(_components.code,{children:`turn_approval=True`}),`: the human approves once, and approved risk labels don’t re-trigger for the rest of the turn.`]}),`\n`,_jsx(Heading,{level:`2`,id:`re-exports`,children:`Re-exports`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`JudgePolicy`}),`, `,_jsx(_components.code,{children:`JudgeVerdict`}),`, `,_jsx(_components.code,{children:`JudgeContext`}),`, `,_jsx(_components.code,{children:`JudgeAction`}),`, and `,_jsx(_components.code,{children:`judged`}),` re-export from `,_jsx(_components.code,{children:`tenet_client`}),` — import from either package.`]}),`\n`,_jsx(Heading,{level:`2`,id:`links`,children:`Links`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/guides/langchain`,children:`LangChain guide — setup and recipes`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/guides/policies`,children:`Policies`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/sdk/tenet-client`,children:`tenet-client reference`})}),`\n`,_jsx(_components.li,{children:_jsxs(_components.a,{href:`https://pypi.org/project/tenet-langchain/`,children:[_jsx(_components.code,{children:`tenet-langchain`}),` on PyPI`]})}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"tenet-langchain","description":"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.","href":"/sdk/tenet-langchain"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"TenetJudgeMiddleware","slug":"tenetjudgemiddleware","depth":2,"children":[]},{"title":"Read intent","slug":"read-intent","depth":2,"children":[{"title":"Safety contract — tool_post-only, enforced in code","slug":"safety-contract-—-tool_post-only-enforced-in-code","depth":3,"children":[]}]},{"title":"Tell the judge what the tool does","slug":"tell-the-judge-what-the-tool-does","depth":2,"children":[]},{"title":"Record every decision","slug":"record-every-decision","depth":2,"children":[]},{"title":"Try it before you enforce it","slug":"try-it-before-you-enforce-it","depth":2,"children":[]},{"title":"Make sure every tool is classified","slug":"make-sure-every-tool-is-classified","depth":2,"children":[]},{"title":"Recursion limit","slug":"recursion-limit","depth":2,"children":[]},{"title":"Human review","slug":"human-review","depth":2,"children":[]},{"title":"Reviews that survive a restart","slug":"reviews-that-survive-a-restart","depth":2,"children":[{"title":"Rewrites and refusals","slug":"rewrites-and-refusals","depth":3,"children":[]}]},{"title":"Per-thread state","slug":"per-thread-state","depth":2,"children":[]},{"title":"Timeouts","slug":"timeouts","depth":2,"children":[]},{"title":"ToolGuardMiddleware","slug":"toolguardmiddleware","depth":2,"children":[]},{"title":"Adjacent classes","slug":"adjacent-classes","depth":2,"children":[]},{"title":"HITL display helpers","slug":"hitl-display-helpers","depth":2,"children":[]},{"title":"Re-exports","slug":"re-exports","depth":2,"children":[]},{"title":"Links","slug":"links","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"tenetlabs","siteName":"Tenet Labs","title":"tenet-langchain - Tenet Labs","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-19T14:34:46.934Z","originalFileLocation":"sdk/tenet-langchain.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Tenet Labs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"tenet-langchain - Tenet Labs\">\u003cmeta data-mint-head property=\"og:description\" content=\"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Tenet Labs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.tenetlabs.com/sdk/tenet-langchain\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://tenetlabs.mintlify.site/_mintlify/api/og/v2?division=SDK+Reference\u0026amp;title=tenet-langchain\u0026amp;description=LangChain+integration+reference+%E2%80%94+TenetJudgeMiddleware%2C+read+intent%2C+HITL+display+helpers%2C+and+adjacent+classes.\u0026amp;theme=391546b21e00cc0a494931a4\u0026amp;signature=b4a8d94b14568d0180d3c4250798991d9be3bb63c62005bc2f0cc0c2691a2e3e\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"tenet-langchain - Tenet Labs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://tenetlabs.mintlify.site/_mintlify/api/og/v2?division=SDK+Reference\u0026amp;title=tenet-langchain\u0026amp;description=LangChain+integration+reference+%E2%80%94+TenetJudgeMiddleware%2C+read+intent%2C+HITL+display+helpers%2C+and+adjacent+classes.\u0026amp;theme=391546b21e00cc0a494931a4\u0026amp;signature=b4a8d94b14568d0180d3c4250798991d9be3bb63c62005bc2f0cc0c2691a2e3e\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/tenetlabs/KiptfhnHYoT5u1IQ/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Tenet Labs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#254BB0\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.tenetlabs.com/sdk/tenet-langchain\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sdk/tenet-langchain.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.tenetlabs.com/#organization\",\"name\":\"Tenet Labs\",\"url\":\"https://docs.tenetlabs.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/tenetlabs/Ux15lHnF6gElpQTR/logo/light.svg?fit=max\u0026auto=format\u0026n=Ux15lHnF6gElpQTR\u0026q=85\u0026s=ad2a07649adcf4d8be428b5187f69dd3\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.tenetlabs.com#website\",\"name\":\"Tenet Labs\",\"url\":\"https://docs.tenetlabs.com\",\"publisher\":{\"@id\":\"https://docs.tenetlabs.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.tenetlabs.com/sdk/tenet-langchain#webpage\",\"url\":\"https://docs.tenetlabs.com/sdk/tenet-langchain\",\"name\":\"tenet-langchain\",\"description\":\"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\",\"dateModified\":\"2026-11-19T14:34:46.934Z\",\"isPartOf\":{\"@id\":\"https://docs.tenetlabs.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.tenetlabs.com/sdk/tenet-langchain#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.tenetlabs.com/sdk/tenet-langchain#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDK Reference\",\"item\":\"https://docs.tenetlabs.com/sdk/tenet-client\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"tenet-langchain\",\"item\":\"https://docs.tenetlabs.com/sdk/tenet-langchain\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.tenetlabs.com/sdk/tenet-langchain#article\",\"headline\":\"tenet-langchain\",\"name\":\"tenet-langchain\",\"description\":\"LangChain integration reference — TenetJudgeMiddleware, read intent, HITL display helpers, and adjacent classes.\",\"url\":\"https://docs.tenetlabs.com/sdk/tenet-langchain\",\"mainEntityOfPage\":{\"@id\":\"https://docs.tenetlabs.com/sdk/tenet-langchain#webpage\"},\"dateModified\":\"2026-11-19T14:34:46.934Z\",\"publisher\":{\"@id\":\"https://docs.tenetlabs.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.tenetlabs.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Tenet Labs\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Tenet Labs\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/sdk/tenet-langchain.md","siteName":"Tenet Labs","nav":{"global":null,"products":[{"product":"Tenet Guardrails","icon":"gavel","description":"Guardrails for agent tool calls, decided by the Judge","tabs":[{"tab":"Documentation","groups":[{"group":"Getting Started","pages":[{"title":"Tenet Guardrails","href":""},{"title":"What is Tenet","href":"/what-is-tenet"},{"title":"Quickstart","href":"/quickstart"},{"title":"Authentication","href":"/authentication"},{"title":"Agent integration","href":"/agent-integration"}]},{"group":"Concepts","pages":[{"title":"Multi-verdict responses","href":"/concepts/multi-verdict"},{"title":"Read-intent \u0026 wire contract","href":"/concepts/read-intent"},{"title":"Surfaces","href":"/concepts/surfaces"},{"title":"Tool context","href":"/concepts/tool-context"},{"title":"How the Judge decides","href":"/concepts/decisions"},{"title":"Verdict Traces","href":"/concepts/traces"}]},{"group":"Guides","pages":[{"title":"LangChain middleware","href":"/guides/langchain"},{"title":"Policies","href":"/guides/policies"},{"title":"Human-in-the-loop review","href":"/guides/hitl"},{"title":"Severity and review rates","href":"/guides/tuning"},{"title":"Verdict-first streaming","href":"/guides/streaming"},{"title":"Voice guardrails","href":"/guides/voice"},{"title":"Framework-free integration","href":"/guides/framework-free"}]},{"group":"SDK Reference","pages":[{"title":"tenet-client","description":"Python SDK reference — TenetCloudJudgeClient, response models, policies, and the @judged decorator.","href":"/sdk/tenet-client"},{"title":"tenet-langchain","href":"/sdk/tenet-langchain"}]}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog"}]}]},{"product":"PII Engine (Enterprise)","icon":"shield-halved","description":"De-identification that runs in your AWS account","pages":[{"title":"PII Engine (Enterprise)","href":"/pii-engine/overview"}]}]},"basePath":"","title":"tenet-langchain - Tenet Labs","deploymentId":"dpl_BEYRRXz1HkchnQ2yWX4JUQCbQT5Q","buildId":"dpl_BEYRRXz1HkchnQ2yWX4JUQCbQT5Q","dynamics":[],"chunks":[]}