Skip to main content

Gateplex Python SDK

Real-time AI governance firewall for LLM applications. Drop-in intercept logging, PII detection, spend controls, and human-in-the-loop approval workflows — deployable inside your VPC.

Installation

pip install gateplex-python

Quick start

from gateplex import GateplexClient

client = GateplexClient(api_key="gp-...")

response = client.log_intercept(
    agent_id="<your-agent-uuid>",
    event_type="llm_call",
    input="Summarise the patient record for John Smith",
    output="John Smith, DOB 1982-03-14, diagnosis: ...",
)

if response.is_blocked:
    raise RuntimeError("Request blocked by governance policy")

print(response.verdict, response.pii_types_detected)

Verdict values

Verdict Meaning
ALLOW Request passed all rules
FLAG Request flagged for audit; execution continues
BLOCK Request blocked; raise GateplexBlockedError
PENDING_APPROVAL Awaiting human reviewer approval

log_intercept automatically raises GateplexBlockedError on a BLOCK verdict.

Human-in-the-loop approvals

from gateplex import GateplexClient, GateplexRejectedError

client = GateplexClient(api_key="gp-...")

try:
    response = client.log_intercept(
        agent_id="<agent-uuid>",
        event_type="llm_call",
        input=user_prompt,
        output=llm_output,
        wait_for_approval=True,   # blocks until reviewer acts
        poll_timeout=600,         # seconds (default 300)
    )
except GateplexRejectedError as e:
    print("Reviewer rejected the request:", e)

You can also poll manually:

response = client.log_intercept(...)

if response.is_pending_approval:
    approval = client.wait_for_approval(response.intercept_id)
    print(approval.status, approval.reviewer_note)

InterceptResponse fields (v0.2.3)

response.intercept_id        # str
response.verdict             # "ALLOW" | "FLAG" | "BLOCK" | "PENDING_APPROVAL"
response.reasoning           # str — human-readable explanation
response.triggered_rules     # List[str] — rule IDs/names that fired
response.pii_types_detected  # List[str] — e.g. ["EMAIL", "SSN"]
response.transaction_amount  # Optional[float]
response.requires_approval   # bool

# Convenience properties
response.is_allowed
response.is_flagged
response.is_blocked
response.is_pending_approval

ApprovalStatus fields (v0.2.3)

approval.intercept_id   # str
approval.status         # "PENDING" | "APPROVED" | "REJECTED"
approval.reviewed_by    # Optional[str]
approval.reviewed_at    # Optional[str] — ISO 8601
approval.reviewer_note  # Optional[str]

approval.is_approved
approval.is_rejected
approval.is_pending

Background batch logging

# Fire-and-forget — does not block the hot path
client.batch_intercept(
    agent_id="<agent-uuid>",
    event_type="llm_call",
    input=prompt,
    output=completion,
)

# Drain the queue before process exit
client.flush()

LLM library integrations

from gateplex.integrations import OpenAIPatcher, AnthropicPatcher
import openai

openai_client = openai.OpenAI(api_key="sk-...")
patcher = OpenAIPatcher(client, agent_id="<agent-uuid>", openai_client=openai_client)
patcher.patch()
# All openai_client.chat.completions.create calls are now logged automatically
patcher.unpatch()

@monitor decorator

from gateplex.integrations import monitor

@monitor(client, agent_id="<agent-uuid>", event_type="llm_call")
def call_llm(input: str) -> str:
    return my_llm(input)

Exceptions

Exception When raised
GateplexAuthError Invalid or missing API key
GateplexAPIError HTTP error from the Gateplex API
GateplexValidationError Malformed request payload
GateplexBlockedError Verdict is BLOCK
GateplexRejectedError Human reviewer rejected a PENDING_APPROVAL intercept

Context manager

with GateplexClient(api_key="gp-...") as client:
    client.log_intercept(...)

Changelog

0.2.3

  • InterceptResponse gains verdict, reasoning, triggered_rules, pii_types_detected, transaction_amount, requires_approval, and is_* convenience properties.
  • New ApprovalStatus dataclass.
  • GateplexClient.wait_for_approval() — polls until approval resolves.
  • log_intercept gains wait_for_approval parameter.
  • New GateplexBlockedError and GateplexRejectedError exceptions.
  • Guardrail gains requires_approval field.

0.2.2

  • @monitor decorator and OpenAIPatcher / AnthropicPatcher integrations.

0.2.1

  • Initial public release.

Download files

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

Source Distribution

gateplex_python-0.2.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

gateplex_python-0.2.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file gateplex_python-0.2.3.tar.gz.

File metadata

  • Download URL: gateplex_python-0.2.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for gateplex_python-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d76d9bbce38379d31bfe8d5054b4b33f91b398b90f87a35cb20f4f6ae23340b5
MD5 ce9e40befc606c692fd68b0958235773
BLAKE2b-256 3517f6bb12b4d5de4dcd775bfb4a156da4b9720cfd2b2c081bb315b6dc31b5c5

See more details on using hashes here.

File details

Details for the file gateplex_python-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gateplex_python-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24784e2f1a1796de73df36ec7687e8db8cfe11a39988b27b9bb1ee1a252c7552
MD5 ff18f6833307448506667be84e439420
BLAKE2b-256 52153cd1f0eacaf8ff18957e568167e0dc15c3e88e4aa0a5d02c3654b3afde60

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

Supported by

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