Files
wehub-resource-sync 97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:36:38 +08:00

2.2 KiB

title, description
title description
Databricks Guide to using instructor with Databricks models

Structured outputs with Databricks, a complete guide w/ instructor

Databricks provides an AI platform with access to various models. This guide shows how to use instructor with Databricks to get structured outputs.

Quick Start

First, install the required packages:

uv pip install instructor openai

Set your Databricks workspace URL and token as environment variables:

export DATABRICKS_TOKEN="your_personal_access_token"
export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"

DATABRICKS_API_KEY and DATABRICKS_WORKSPACE_URL are also supported if you prefer those names. The provider appends /serving-endpoints automatically, so the host only needs the base workspace URL.

Basic Example

Here's how to extract structured data from Databricks models:

import instructor
from pydantic import BaseModel

# Initialize the client; host and token are read from the environment
client = instructor.from_provider(
    "databricks/dbrx-instruct",
    mode=instructor.Mode.TOOLS,
)

# Define your data structure
class UserExtract(BaseModel):
    name: str
    age: int

# Extract structured data
user = client.create(
    response_model=UserExtract,
    messages=[
        {"role": "user", "content": "Extract jason is 25 years old"},
    ],
)

print(user)
# Output: UserExtract(name='Jason', age=25)

If you need to point at a different workspace or testing endpoint, pass base_url="https://alt-workspace.cloud.databricks.com/serving-endpoints". The helper will use that value as-is without adding another suffix.

Async Example

async_client = instructor.from_provider(
    "databricks/dbrx-instruct",
    async_client=True,
    mode=instructor.Mode.TOOLS,
)

Supported Modes

Databricks supports the same modes as OpenAI:

  • Mode.TOOLS
  • Mode.JSON
  • Mode.FUNCTIONS
  • Mode.PARALLEL_TOOLS
  • Mode.MD_JSON
  • Mode.TOOLS_STRICT
  • Mode.JSON_O1

Models

Databricks provides access to various models depending on your setup, including:

  • Foundation models hosted on Databricks
  • Custom fine-tuned models
  • Open source models deployed on Databricks