Skip to main content

unifyapps-guardrails

A thin client for UnifyApps platform guardrails. Checks are not run in this process — they are config-driven controls (Denied Topics, Content Filter, PII, Prompt Injection, Custom terms, Regex, Credentials, Blocked Tools, Custom LLM) grouped into policies applied to an agent. This client calls the exported Governance | Inline Evaluate endpoint, which resolves the agent's controls for a given surface, runs only those, writes incidents itself, and returns one decision.

Add or remove a control in the UI and the same code enforces it — nothing about the checks is hardcoded here. Every call emits an OpenTelemetry span so it nests inside your existing UnifyApps trace.

Install

pip install unifyapps-guardrails

Or, from a clone (editable):

pip install -e .

Stdlib + opentelemetry-api only — no models to download, no heavy deps.

Configure

Env var Purpose
UNIFYAPPS_GUARDRAILS_URL URL of the exported inline-evaluate callable, with the agent id as its last path segment (like the OTLP endpoint)
UNIFYAPPS_GUARDRAILS_API_KEY optional; sent as Authorization: Bearer <key>

Usage

from unifyapps.guardrails import GovernanceGuard

# agent id comes from UNIFYAPPS_GUARDRAILS_URL's path — nothing to pass here
guard = GovernanceGuard()

# Before the LLM sees the user's message
d = guard.check_user_input(user_text)
if d.block:
    return d.content          # refusal message — don't call the LLM
user_text = d.content         # masked/clean text to send to the LLM

# After the LLM answers, before the user sees it
d = guard.check_agent_output(reply)
return d.content              # block -> refusal; else masked/clean text

The decision

evaluate / check_user_input / check_agent_output return a GovernanceDecision:

Field Meaning
block True if the content must be withheld
content the text to use: masked/clean when block=False, the refusal message when block=True
raw the full endpoint payload

Only user_input and agent_output are enforced (see Surface); tool surfaces are out of scope. The guard fails open — on timeout or endpoint error it returns the original text with block=False, so a guardrail outage never drops a turn.

Endpoint contract

POST <UNIFYAPPS_GUARDRAILS_URL>          # .../<agent-id>  (id is the last path segment)
body  -> { content, inputType, caseId }
200   -> { block: bool, content: str }

The agent id is the last path segment of the URL, not a body field — same shape as the OTLP collector endpoint, so it is never passed twice. It is both the policy lookup key and the incident scope; the exported callable maps that path segment to its agentId input. inputType is the surface (user_input / agent_output). caseId is any stable per-conversation id (the client defaults to a random uuid) so the resolver takes the chat branch.

Examples

Full input + output turns, one per framework, in examples/:

Framework File
LangChain examples/langchain_unify_guardrails.py
LangGraph examples/langgraph_unify_guardrails.py
OpenAI Agents SDK examples/openai_agents_unify_guardrails.py

License

Apache 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unifyapps_guardrails-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file unifyapps_guardrails-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: unifyapps_guardrails-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for unifyapps_guardrails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7fb26ec9e6d41a1d9bcc1b493942ccb8ab97e1b09d14977ae4ec0f9a3ffcf47
MD5 6d975746a21f0b74d9d725319334b601
BLAKE2b-256 8f56187c16ace047ab4b32cfdbc213909ad7ae7bec28511b7eb48a41b0bf671c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page