Skip to main content

Official Governance AI SDK for Python runtimes and guardrails instrumentation

Project description

Governance AI SDK for Python

SDK oficial de Python para integrar runtimes con Governance AI Guardrails.

Publicacion objetivo en PyPI:

pip install governanceai

El paquete mantiene compatibilidad con el import legado governance_guardrails_sdk, pero el nombre canonico nuevo es governanceai.

API cubierta

  • POST /guardrails/install
  • POST /guardrails/evaluate
  • POST /guardrails/heartbeat
  • POST /guardrails/events

Autenticacion

El SDK usa:

  • app_number en el body
  • Authorization: Bearer <APP_API_KEY> en cada request

Quick start

from governanceai import GovernanceAIClient, GovernanceAIError

client = GovernanceAIClient(
    base_url="https://api.governanceai.example",
    app_number=123456,
    app_api_key="ga_live_replace_me",
    timeout_seconds=10,
    max_retries=2,
)

try:
    client.install(mode="monitor", metadata={"environment": "production"})
    client.heartbeat()

    decision = client.apply("Summarize this support ticket", stage="input")
    print(decision.allowed, decision.findings, decision.selected_validators)
except GovernanceAIError as exc:
    print(exc.status_code, exc)

Ejemplo real de flujo runtime

from governanceai import GovernanceAIClient

client = GovernanceAIClient(
    base_url="https://api.governanceai.example",
    app_number=123456,
    app_api_key="ga_live_replace_me",
    default_policy_id="default-runtime-policy",
)

decision_in = client.apply(user_prompt, stage="input")
if not decision_in.allowed:
    raise RuntimeError(decision_in.findings)

model_reply = llm.invoke(user_prompt)
decision_out = client.apply(model_reply, stage="output")
if not decision_out.allowed:
    raise RuntimeError(decision_out.findings)

Manejo de errores, timeout y retry

GovernanceAIClient expone:

  • timeout_seconds
  • max_retries
  • retry_backoff_seconds
  • retry_status_codes

Los errores del SDK levantan GovernanceAIError con:

  • status_code
  • response_body

Los retries se aplican a errores de red y a respuestas transientes como 408, 429, 500, 502, 503 y 504.

Capabilities

install()

Registra el runtime y devuelve el estado efectivo de guardrails.

heartbeat()

Mantiene la señal de vida del runtime y puede enviar telemetría agregada del SDK.

apply()

Evalua texto runtime con soporte para:

  • policy_id
  • mode
  • stage
  • tool_calls
  • metadata
  • include_telemetry

Respuesta:

  • allowed
  • output_text
  • findings
  • selected_validators
  • effective_scope
  • mode

record_event()

Emite eventos custom al backend.

report_redteam_probe()

Atajo para registrar event_type=redteam_probe.

Ejemplo con tool calls

decision = client.apply(
    "Open the customer export",
    stage="tool",
    tool_calls=[
        {
            "tool_name": "browser.fetch",
            "url": "https://example.com/private-report",
        }
    ],
)
print(decision.allowed)

Si el dominio no esta permitido por la configuracion de la aplicacion, el backend puede responder bloqueando la operacion.

Tests y release

Instalacion editable:

pip install -e ./sdk/python

Ejecutar tests:

python -m pytest ./sdk/python/tests

Build:

python -m build ./sdk/python

Publicacion:

python -m twine upload dist/*

Semver y changelog

Referencias

Project details


Download files

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

Source Distribution

governanceai-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

governanceai-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file governanceai-0.1.0.tar.gz.

File metadata

  • Download URL: governanceai-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for governanceai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c98e47784ca1db6c0c4a9b1e1c186730fbcf6722982ab27d1b86cc8460e69fe1
MD5 86e847a0183b6b4732179eb648ba23f1
BLAKE2b-256 198b020865f4528de3b8ab6ccde38989081a33ae8e2e2b0e47bbe118326296d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for governanceai-0.1.0.tar.gz:

Publisher: publish-pypi.yml on l33tm3/governanceai-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: governanceai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for governanceai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e1eb4d930f7e9f90cf24554833d937ca76f9fcab00b2761dbe57bf9b3dd2fb0
MD5 78f34e2ec3e12185845cafd62bbbec56
BLAKE2b-256 4af440b5f27575839dfa31480826d4e97a88303a36145fde7a3b211951aac57b

See more details on using hashes here.

Provenance

The following attestation bundles were made for governanceai-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on l33tm3/governanceai-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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