Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page
Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.
{
  "mcpServers": {
    "respan-docs": {
      "url": "https://respan.ai/docs/mcp"
    }
  }
}

What is Instructor?

Instructor is a Python library for getting structured data (JSON) from LLMs using Pydantic models. It patches OpenAI and other LLM clients to return validated, typed responses. The Respan integration uses respan-tracing auto-instrumentation to capture all LLM calls.

Setup

1

Install packages

pip install instructor openai respan-tracing
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
3

Initialize and run

from respan_tracing import RespanTelemetry, workflow, task, Instruments
from openai import OpenAI
import instructor
from pydantic import BaseModel

# Initialize Respan — auto-instruments OpenAI calls
telemetry = RespanTelemetry(instruments={Instruments.OPENAI})

# Patch OpenAI with Instructor
client = instructor.from_openai(OpenAI())

class User(BaseModel):
    name: str
    age: int

@task(name="extract_user")
def extract_user(text: str) -> User:
    return client.chat.completions.create(
        model="gpt-4o-mini",
        response_model=User,
        messages=[{"role": "user", "content": f"Extract user info: {text}"}],
    )

@workflow(name="extraction_pipeline")
def extraction_pipeline():
    user = extract_user("John is 30 years old")
    print(f"Name: {user.name}, Age: {user.age}")
    return user

extraction_pipeline()
4

View your trace

Open the Traces page to see your extraction traces.

Configuration

Instructor uses the respan-tracing SDK. Instruments.OPENAI auto-captures all OpenAI calls made by Instructor. See the Python Tracing SDK reference for configuration options.