Skip to main content

Respan instrumentation plugin for Guardrails AI

Project description

respan-instrumentation-guardrails

Respan instrumentation plugin for Guardrails AI. It wraps Guardrails Guard execution methods and emits guardrail spans into the Respan tracing pipeline.

Configuration

1. Install

pip install respan-ai respan-instrumentation-guardrails guardrails-ai

guardrails-ai is the Guardrails runtime package. It must be available in your package index for runnable Guardrails applications.

2. Set Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Your Respan API key. Authenticates both proxy and tracing.
RESPAN_BASE_URL No Defaults to https://api.respan.ai/api.

Quickstart

3. Run Script

import os

from dotenv import load_dotenv

load_dotenv()

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")
os.environ["OPENAI_API_KEY"] = respan_api_key
os.environ["OPENAI_BASE_URL"] = respan_base_url

from guardrails import Guard
from pydantic import BaseModel
from respan import Respan
from respan_instrumentation_guardrails import GuardrailsInstrumentor


class SupportReply(BaseModel):
    answer: str
    priority: str


respan = Respan(
    api_key=respan_api_key,
    base_url=respan_base_url,
    instrumentations=[GuardrailsInstrumentor()],
)

guard = Guard.for_pydantic(output_class=SupportReply)
result = guard(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": "Return JSON with answer and priority for a late shipment.",
        }
    ],
)

print(result.validated_output)
respan.flush()

4. View Dashboard

After running the script, traces appear on your Respan dashboard.

Further Reading

See the Respan example projects for runnable scripts.

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

respan_instrumentation_guardrails-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file respan_instrumentation_guardrails-0.1.0.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_guardrails-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59a2844a676eee4f62a862301dbd5d67212fdaacaefbe2e37093886bc5df419a
MD5 8ec41b4026c61b988e4655ad0f3c4bf7
BLAKE2b-256 6c4c745ab656b0290bc02768f9d9ae96578f770b8e278e59408a3ea154d96c9d

See more details on using hashes here.

File details

Details for the file respan_instrumentation_guardrails-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_guardrails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88398e78883f0921a6a45e2c45e3443c294be2e1a94cb3daa6a3958066ca157a
MD5 aa68dc3e9a51c79bb262cde2b2c0b756
BLAKE2b-256 9c052096cb8d13e160ad800313e06df7325c7aa0656c2217ed06982147f9cf7c

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