Skip to main content

conduct-litellm-guard

Conduct Guard as a LiteLLM guardrail. Every LLM call routed through LiteLLM runs through your active Guard policy before the request leaves your network — block, warn, audit, or trigger a HITL approval, with the same signed configuration and hash-chained audit log as the rest of Conduct.

Install

pip install conduct-litellm-guard

Wire it up

For optional user-delegated identity, see Federation setup. It uses a separate service credential and trusted custom-auth handoff; the service-only setup below is unchanged.

  1. Mint an agent token in the Conduct console (Settings → Agent identities). Copy the cond_agt_… value.

  2. Export it in the environment where your LiteLLM proxy runs:

    export CONDUCT_AGENT_TOKEN=cond_agt_...
    
  3. Add the guardrail to your LiteLLM proxy's config.yaml. Two forms — both work today, they differ only in the guardrail: string:

    Explicit (works on any LiteLLM version):

    guardrails:
      - guardrail_name: conduct-guard
        litellm_params:
          guardrail: conduct_litellm_guard.ConductGuard
          mode: [pre_call, pre_mcp_call]
          api_url: https://gateway.conductai.ai
          agent_token: os.environ/CONDUCT_AGENT_TOKEN
          unreachable_fallback: fail_closed
    

    Native (LiteLLM with BerriAI/litellm#40785):

    guardrails:
      - guardrail_name: conduct-guard
        litellm_params:
          guardrail: conduct
          mode: [pre_call, pre_mcp_call]
          api_key: os.environ/CONDUCT_AGENT_TOKEN
          unreachable_fallback: fail_closed
    

    The native form uses LiteLLM's idiomatic api_base / api_key parameter names. You still install this package — pip install conduct-litellm-guard — because the native adapter is a thin wrapper that imports from it. Same pattern Aporia and Lakera use.

  4. Start the proxy:

    litellm --config config.yaml
    

A full example lives in examples/config.yaml.

What the guardrail does

For every incoming request the guardrail calls Conduct's guard_check tool (JSON-RPC over the MCP endpoint) with a compact summary of the LiteLLM request — model, call type, message count, temperature, stream flag, plus the last user message so the audit trail carries context.

Guard returns one of five verdicts:

Verdict LiteLLM behaviour
ok / allow Request forwarded to the upstream model.
advisory Forwarded, metadata.conduct_guard annotated.
WARNING Forwarded, warning surfaced in metadata.
BLOCKED LiteLLM returns an error to the caller. No upstream token spent.
PENDING approval Blocked pending HITL. Caller receives an error citing the rule.

MCP tool calls (pre_mcp_call, 0.2.7+)

When LiteLLM's MCP gateway runs a tool, the guardrail also calls Guard's guard_check action gate with the real tool name and arguments, the same check the CLI hook uses. Rules on tool + arguments (block, approval) apply to MCP traffic. The prompt check still scans the arguments for credentials / PII. The most severe verdict wins. Drop pre_mcp_call from mode: to keep the guardrail LLM-only.

Configuration reference

Field Required Default Notes
api_url no https://gateway.conductai.ai Point at a self-hosted Conduct API when needed.
agent_token yes CONDUCT_AGENT_TOKEN env cond_agt_* token minted in the Conduct console.
workspace_id no resolved from the token Usually unnecessary — the token owns its workspace.
unreachable_fallback no fail_closed fail_closed blocks when Guard is unreachable, fail_open allows. Renamed from fail_mode in v0.2.5 — the old name still works with a DeprecationWarning and is removed in v0.3.0.
timeout no 8.0 Seconds. Guard checks return in <100ms in the healthy path.

Session tracking

Guard uses a session ID to correlate the pre-call check with any resume-verdict / HITL approval that follows. The adapter picks the first value it finds in this order:

  1. litellm_metadata.trace_id
  2. metadata.X-Conduct-Session-Id (explicit override — set this if you want deterministic control over the session boundary).
  3. metadata.conduct_session_id.
  4. A deterministic hash of the user field plus the first user message.

If none of the above are available and the caller sends no user or messages, session tracking is skipped (single-shot mode). Approvals still work — they just can't be resumed against a prior check.

Fail modes

  • fail_closed (default) — blocks the call if Guard is unreachable or the policy evaluator errors. Matches Conduct's default posture across every other enforcement surface.
  • fail_open — allows the call and logs a warning. Use during rollout or if Guard is a soft dependency for your setup.

License

conduct-litellm-guard is distributed under the Apache License 2.0, the same license as the rest of Conduct.

  • Conduct Guard — the policy engine.
  • Conduct Router — Conduct's own LLM proxy.
  • Source — this package lives under packages/conduct-litellm-guard/.
  • Issues — file bugs and requests against the parent repo.

Metadata

Release files for conduct-litellm-guard 0.2.7

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

Source distribution (sdist)

Source distribution for conduct-litellm-guard 0.2.7
File Size Uploaded
conduct_litellm_guard-0.2.7.tar.gz 25.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for conduct-litellm-guard 0.2.7
File Interpreter ABI Platform
conduct_litellm_guard-0.2.7-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / conduct_litellm_guard-0.2.7.tar.gz

Download URL conduct_litellm_guard-0.2.7.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5641e1d14f9d5604e25808417fb729b1154f738e66599e35e164826be6256927
BLAKE2b-256 checksum
How to use checksums
4472852d94c6d41fc99b97b52c62f6fff0581b6723615926c7a6f37969483496
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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

PyPI Publish Attestation

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

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release files / conduct_litellm_guard-0.2.7-py3-none-any.whl

Download URL conduct_litellm_guard-0.2.7-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7152e54a675a1b75fe8c038cbf00672fa40ee559b87233b26950d580c6c12b39
BLAKE2b-256 checksum
How to use checksums
62eb6b97b733c474712bbeaf85fa0f9957631db6f68f3b3e85b7eb4360f5ef41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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

PyPI Publish Attestation

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

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.7 This release

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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