Skip to main content

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


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.3.1.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

guardrails_ai_sdk-0.3.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file guardrails_ai_sdk-0.3.1.tar.gz.

File metadata

  • Download URL: guardrails_ai_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for guardrails_ai_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5179c5ac505be00cc017b83500835b6aa9439e4c2655c707659588a6e5533dd7
MD5 2b9bc8f171d096768755a193d14266b4
BLAKE2b-256 fe0800291f9a501d10e74867af79d3876c572bfdca106d091026555c94b7fd89

See more details on using hashes here.

File details

Details for the file guardrails_ai_sdk-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for guardrails_ai_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57ebec4dbff3e5e28b15fcfadb8b9efc7f53d59a728bbbe4f6b170811575559f
MD5 e7a2e0733dd2b50c7e2d747c9cf72112
BLAKE2b-256 69b497d7a90532301888d165ae407a079b26e31dce557699edf8a7237745bc94

See more details on using hashes here.

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