> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenetlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Framework-free integration

> Gate any Python function with @judged, or call the judge directly when you own the tool loop. No LangChain required.

**`tenet-client` standalone**: pure Python + httpx + pydantic — no framework dependency. Two integration shapes: the `@judged` decorator for drop-in gating, and `evaluate()` / `evaluate_phase()` when you own the dispatch loop.

If your harness is LangChain, use the [middleware](https://docs.tenetlabs.com/guides/langchain.md) instead — it handles retry nudges, verdict caching, and session threading you'd otherwise rebuild.

## `@judged` — gate a function

```python theme={null}
# Python — works on sync and async functions.
from tenet_client import TenetCloudJudgeClient, judged, JudgeBlocked

judge = TenetCloudJudgeClient.from_env()
judge.warmup()

@judged(judge)
def search_resumes(query: str) -> list[dict]:
    return _fetch(query)

@judged(judge, check_post=False)        # judge args only — output is just IDs
async def archive_candidate(candidate_id: str) -> None:
    await _archive(candidate_id)

try:
    hits = search_resumes("backend engineers, no visa sponsorship")
except JudgeBlocked as e:
    # e.phase ("tool_pre" | "tool_post"), e.reason, e.tool_name, e.judge_id
    handle_block(e)
```

Options: `tool_name` (defaults to the function name), `check_pre` / `check_post`, `fail_open` (default `False` — keep it that way for side-effectful functions), `policy`, `input_builder` / `output_builder` to shape what the judge sees, and `metadata`.

## Direct evaluation — you own the loop

If your harness already has a tool-dispatch choke point, call the judge there:

```python theme={null}
# Python — one gate function covers every tool in the harness.
from tenet_client import TenetCloudJudgeClient, JudgeUnavailableError

judge = TenetCloudJudgeClient.from_env()

# The tool encodes the user's intent — map it to the right surface
# instead of telling the judge everything is a resume screen.
SURFACE_BY_TOOL = {
    "search_resumes": "resume_triage",
    "draft_job_ad": "job_ad_drafting",
    "rank_candidates": "candidate_ranking",
    "draft_outreach_email": "candidate_outreach",
}

def gate(tool_name: str, tool_input: dict) -> str | None:
    """Returns a user-facing message if blocked, None if clear."""
    try:
        v = judge.evaluate(
            phase="tool_pre",
            tool_name=tool_name,
            tool_input=tool_input,
            surface=SURFACE_BY_TOOL.get(tool_name, "resume_triage"),  # unmapped → the default
        )
    except JudgeUnavailableError:
        return "Compliance check unavailable — action not taken."  # fail closed
    if v.decision == "block":
        return v.safe_message or "Blocked by compliance."
    return None
```

The dispatch loop is the natural place to set [`surface`](https://docs.tenetlabs.com/concepts/surfaces) — the judge reads it to frame the ask, and the tool name already tells you which recruiting action this is.

`evaluate_async()` is the same call shape for async harnesses. Both return a [`CloudJudgeResponse`](https://docs.tenetlabs.com/sdk/tenet-client#cloudjudgeresponse).

For verdict → action mapping without writing branches, use `evaluate_phase(policy=..., phase=...)` — it returns `(JudgeVerdict, JudgeAction)` with your [policy](https://docs.tenetlabs.com/guides/policies.md) already applied.

## Multi-turn context

A single tool call can look benign while the conversation isn't. Send the session and prior turns:

```python theme={null}
v = judge.evaluate(
    phase="tool_pre",
    tool_input={"query": "ones who can start immediately"},
    session_id="conv-8841",                       # groups the audit trace
    prior_user_turns=[                            # oldest first
        "find recent grads",
        "filter to people without kids",
    ],
)
```

Without `prior_user_turns`, the judge sees each call cold — "ones who can start immediately" judged alone misses what it's filtering.

## Gotchas

* **`@judged` judges under the client's `surface`** — there's no per-call override on the decorator path. Fine when every decorated tool is the same action kind; for mixed toolsets (screening + drafting + outreach), use the dispatch-loop pattern above with `surface=` per call. See [Surfaces](https://docs.tenetlabs.com/concepts/surfaces.md).
* **One client per process.** The client holds the access token cache and connection pool. Construct at startup, `warmup()`, reuse everywhere. `close()` / `aclose()` on shutdown.
* **`fail_open=True` is per-function, deliberate, and logged** — never the default. A guardrail that silently disappears under load isn't a guardrail.
* **Timeout is 3.0s by default.** A judge call can exceed it; the SDK raises `JudgeUnavailableError` on timeout. If you'd rather wait than fail, raise `timeout=` — size it from the `latency_ms` your traffic sees.

## Links

* [Surfaces — the tool → surface map](https://docs.tenetlabs.com/concepts/surfaces.md)
* [Policies](https://docs.tenetlabs.com/guides/policies.md)
* [tenet-client reference](https://docs.tenetlabs.com/sdk/tenet-client.md)
* [API Reference — call the wire protocol directly](https://docs.tenetlabs.com/api-reference/introduction.md)

| Integration | Shape | Use when |
| - | - | - |
| [`TenetJudgeMiddleware`](https://docs.tenetlabs.com/guides/langchain) | LangChain `AgentMiddleware` | `create_agent` harnesses |
| `@judged` / `evaluate()` | Python decorator / SDK call | Any Python harness — this page |
| [HTTP API](https://docs.tenetlabs.com/api-reference/introduction.md) | REST + SSE | Non-Python harnesses |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.