Skip to main content

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)

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_types-0.5.0.tar.gz (17.2 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_types-0.5.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file guardrails_ai_types-0.5.0.tar.gz.

File metadata

  • Download URL: guardrails_ai_types-0.5.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for guardrails_ai_types-0.5.0.tar.gz
Algorithm Hash digest
SHA256 de872718c09c7560ee4b79190f6b10f994983c1c90df1b774c8a4df422fe835f
MD5 6c3e960ebb99526f5214248ffbb86fb3
BLAKE2b-256 f8b5aa41b36e4859424c3bc98a9e81e22bb7e0f159ff19bbd5bed91aa9b36a85

See more details on using hashes here.

Provenance

The following attestation bundles were made for guardrails_ai_types-0.5.0.tar.gz:

Publisher: types_py_publish.yml on guardrails-ai/guardrails-ai

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

File details

Details for the file guardrails_ai_types-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for guardrails_ai_types-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc7db51bbe5b5ee0bdb4c50be98522940774f16f3b979c53bf849f004e2c8574
MD5 e3c173a1e0358e7d0cdc287078edb7c9
BLAKE2b-256 666e57318a696733245914392b04677fbac429fa0f8b95f159223abcbe6b909e

See more details on using hashes here.

Provenance

The following attestation bundles were made for guardrails_ai_types-0.5.0-py3-none-any.whl:

Publisher: types_py_publish.yml on guardrails-ai/guardrails-ai

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

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page