Offical Guardrails AI SDK
Project description
guardrails-client
A thin REST client for the guardrails-api.
Quickstart
pip install guardrails-ai-sdk
from guardrails_ai.sdk import GuardrailsAI, Guard, ValidationOutcome
# Init the GuardrailsAI client
client = GuardrailsAI(api_key="xxx")
# Fetch a Guard from the server
guard: Guard = await client.guards.retrieve(name="my-guard")
print(guard)
# Run a Guard to validate content
validation_outcome: ValidationOutcome = await client.guards.validate(name="my-guard", llm_output="Hello, world.")
if not validation_outcome.validation_passed:
print(validation_outcome.validation_summaries)
# Create Guarded Chat Completions
chat_completion = await client.guards.chat.completions.create(guard_name="my-guard", model="gpt-5-nano", messages=[{ "role": "user", "content": "Hello, world." }])
print(chat_completion.choices[0].message.content)
print(chat_completion.guardrails)
# Stream Guarded Chat Completions
completion_stream = await client.guards.chat.completions.create(
guard_name="my-first-guard",
model="gpt-5-nano",
messages=[
{"role": "user", "content": "Give yourself a realistic name and introduce yourself."}
],
stream=True
)
full_text = ""
validation_summaries = []
async for chunk in completion_stream:
full_text += chunk.choices[0].delta.content
validation_summaries.extend(chunk.guardrails.get("validation_summaries", []))
print("\n ==> Validation Summaries: ", validation_summaries)
print("\n ==> Final Content: ", full_text)
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 guardrails_ai_sdk-0.4.0a7.tar.gz.
File metadata
- Download URL: guardrails_ai_sdk-0.4.0a7.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d3cd88e2ee7e44b816cb682153ab0abf31d6b28d0adce9d8316a18ffd8ef92c
|
|
| MD5 |
eeca33acedad28484f49c06e97a3d753
|
|
| BLAKE2b-256 |
215cd77351fc60e94ae1d6b6ec6d533a11b98c1350161235970d5ec50cb3ff73
|
Provenance
The following attestation bundles were made for guardrails_ai_sdk-0.4.0a7.tar.gz:
Publisher:
sdk_py_publish.yml on guardrails-ai/guardrails-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guardrails_ai_sdk-0.4.0a7.tar.gz -
Subject digest:
8d3cd88e2ee7e44b816cb682153ab0abf31d6b28d0adce9d8316a18ffd8ef92c - Sigstore transparency entry: 1723420215
- Sigstore integration time:
-
Permalink:
guardrails-ai/guardrails-ai@9ccfdcb05289a0ee4744e38771fde09d81a0e948 -
Branch / Tag:
refs/heads/feat/trusted-pub - Owner: https://github.com/guardrails-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk_py_publish.yml@9ccfdcb05289a0ee4744e38771fde09d81a0e948 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file guardrails_ai_sdk-0.4.0a7-py3-none-any.whl.
File metadata
- Download URL: guardrails_ai_sdk-0.4.0a7-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
541170183b34f860f6b58bcb22c157d70d710354119039ac3cd953aa456b3706
|
|
| MD5 |
d968543aa1d9df48ccb818235e104684
|
|
| BLAKE2b-256 |
681e95c2915cea5fabdb8486074d7bb2b63596ddf307656ac78cd6b02a903fea
|
Provenance
The following attestation bundles were made for guardrails_ai_sdk-0.4.0a7-py3-none-any.whl:
Publisher:
sdk_py_publish.yml on guardrails-ai/guardrails-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guardrails_ai_sdk-0.4.0a7-py3-none-any.whl -
Subject digest:
541170183b34f860f6b58bcb22c157d70d710354119039ac3cd953aa456b3706 - Sigstore transparency entry: 1723420322
- Sigstore integration time:
-
Permalink:
guardrails-ai/guardrails-ai@9ccfdcb05289a0ee4744e38771fde09d81a0e948 -
Branch / Tag:
refs/heads/feat/trusted-pub - Owner: https://github.com/guardrails-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk_py_publish.yml@9ccfdcb05289a0ee4744e38771fde09d81a0e948 -
Trigger Event:
workflow_dispatch
-
Statement type: