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
guardrails_ai_sdk-0.4.0a1.tar.gz
(14.5 kB
view details)
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.0a1.tar.gz.
File metadata
- Download URL: guardrails_ai_sdk-0.4.0a1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0fc0fa843fcda6158b5a9f5dafba42abb5935ccd2264fc7a3d7c7764e3d9e5f
|
|
| MD5 |
f8ea790f275f8b1848df0b1039fa648d
|
|
| BLAKE2b-256 |
f1d16485fd08d8ba7e70d9738a8aa04173022f09dbd92ffa1f162226396549b5
|
File details
Details for the file guardrails_ai_sdk-0.4.0a1-py3-none-any.whl.
File metadata
- Download URL: guardrails_ai_sdk-0.4.0a1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa7da7d638877783678ea24846f74e7e10428cb98e14dfebc71dcd8539350457
|
|
| MD5 |
d2f0102554a1d204ac27e91b3bb7b2f4
|
|
| BLAKE2b-256 |
be49eb49f47083edd92481d37608f2b9da1f9d0eaa22ac0aeb2bd7d55d2d801c
|