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/installPOST /guardrails/evaluatePOST /guardrails/heartbeatPOST /guardrails/events
Autenticacion
El SDK usa:
app_numberen el bodyAuthorization: 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_secondsmax_retriesretry_backoff_secondsretry_status_codes
Los errores del SDK levantan GovernanceAIError con:
status_coderesponse_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_idmodestagetool_callsmetadatainclude_telemetry
Respuesta:
allowedoutput_textfindingsselected_validatorseffective_scopemode
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
- Version actual:
0.1.0 - Historial:
CHANGELOG.md - Licencia:
LICENSE
Referencias
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c98e47784ca1db6c0c4a9b1e1c186730fbcf6722982ab27d1b86cc8460e69fe1
|
|
| MD5 |
86e847a0183b6b4732179eb648ba23f1
|
|
| BLAKE2b-256 |
198b020865f4528de3b8ab6ccde38989081a33ae8e2e2b0e47bbe118326296d1
|
Provenance
The following attestation bundles were made for governanceai-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on l33tm3/governanceai-guardrails
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
governanceai-0.1.0.tar.gz -
Subject digest:
c98e47784ca1db6c0c4a9b1e1c186730fbcf6722982ab27d1b86cc8460e69fe1 - Sigstore transparency entry: 1154886772
- Sigstore integration time:
-
Permalink:
l33tm3/governanceai-guardrails@2bd84057bbec369b0412adbbbad5f00b791cfe7e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/l33tm3
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2bd84057bbec369b0412adbbbad5f00b791cfe7e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e1eb4d930f7e9f90cf24554833d937ca76f9fcab00b2761dbe57bf9b3dd2fb0
|
|
| MD5 |
78f34e2ec3e12185845cafd62bbbec56
|
|
| BLAKE2b-256 |
4af440b5f27575839dfa31480826d4e97a88303a36145fde7a3b211951aac57b
|
Provenance
The following attestation bundles were made for governanceai-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on l33tm3/governanceai-guardrails
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
governanceai-0.1.0-py3-none-any.whl -
Subject digest:
2e1eb4d930f7e9f90cf24554833d937ca76f9fcab00b2761dbe57bf9b3dd2fb0 - Sigstore transparency entry: 1154886773
- Sigstore integration time:
-
Permalink:
l33tm3/governanceai-guardrails@2bd84057bbec369b0412adbbbad5f00b791cfe7e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/l33tm3
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2bd84057bbec369b0412adbbbad5f00b791cfe7e -
Trigger Event:
push
-
Statement type: