Skip to main content

Overview

Guardrails can wrap any callable compatible with its LLM API interface. For TokenLab, configure the OpenAI SDK with TokenLab’s base URL and pass the chat completions callable to your guard.
Type: Validation and structured-output frameworkPrimary Path: OpenAI-compatible Chat CompletionsSupport Confidence: Supported OpenAI-compatible path

Environment

export TOKENLAB_API_KEY="sk-your-tokenlab-key"

Example

import os

from guardrails import Guard
from openai import OpenAI
from pydantic import BaseModel, Field


class Pet(BaseModel):
    pet_type: str = Field(description="Species of pet")
    name: str = Field(description="A unique pet name")


guard = Guard.for_pydantic(output_class=Pet)

client = OpenAI(
    api_key=os.environ["TOKENLAB_API_KEY"],
    base_url="https://api.tokenlab.sh/v1",
)

raw_output, validated_output, *rest = guard(
    llm_api=client.chat.completions.create,
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "What kind of pet should I get?"}],
)

Endpoint Notes

Guardrails focuses on validation around the LLM call. Use the OpenAI-compatible path for chat-completions flows, or pass a custom callable if your application needs a native TokenLab endpoint.