Instructor

Instructor with an OpenAI-compatible uncensored API

Get validated Pydantic objects from Abliterator with Instructor: from_provider with base_url, TOOLS mode, automatic retries, and streaming with create_partial.

Reviewed InstructorPython

Quick answer

Create the client with instructor.from_provider("openai/kimi-k3.1-pro-abliterated", base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]) and call client.create(response_model=YourModel, messages=[...]).

Instructor turns a chat model into a function that returns validated Pydantic objects. Its OpenAI integration takes a base_url for compatible servers, so pointing it at Abliterator is a one-line change. Tested with instructor 1.18.

Install

pip install instructor
export ABL_API_KEY="sk-abl-v1-..."

Extract a typed object

import os

import instructor
from pydantic import BaseModel, Field


class Indicator(BaseModel):
    kind: str = Field(description="ip, domain, hash or url")
    value: str


class ThreatReport(BaseModel):
    actor: str
    techniques: list[str] = Field(description="MITRE ATT&CK technique IDs")
    indicators: list[Indicator]


client = instructor.from_provider(
    "openai/kimi-k3.1-pro-abliterated",
    base_url="https://abliterator.ai/v1",
    api_key=os.environ["ABL_API_KEY"],
)

report = client.create(
    response_model=ThreatReport,
    messages=[
        {
            "role": "user",
            "content": "Extract from this note: 'The group used spearphishing links (T1566.002) and scheduled tasks "
            "(T1053.005); C2 at 198.51.100.23 and update-check[.]net.'",
        }
    ],
    max_retries=2,
)
print(report.model_dump_json(indent=2))

from_provider builds the OpenAI client for you and defaults to Mode.TOOLS. If validation fails, Instructor sends the error back to the model and asks again, up to max_retries times.

Stream a partial object

create_partial yields the object as fields fill in, which is useful for showing progress on long extractions:

import os

import instructor
from pydantic import BaseModel


class IncidentSummary(BaseModel):
    title: str
    impact: str
    root_cause: str
    actions: list[str]


client = instructor.from_provider(
    "openai/deepseek-v4.1-flash-abliterated",
    base_url="https://abliterator.ai/v1",
    api_key=os.environ["ABL_API_KEY"],
)

for partial in client.create_partial(
    response_model=IncidentSummary,
    messages=[{"role": "user", "content": "Summarize: an expired TLS certificate on the API gateway caused 40 minutes of 5xx errors."}],
):
    print(partial.model_dump(exclude_none=True))

Every field is optional while streaming, so code that reads partial must handle None.

Generate a batch of labeled rows

create_iterable streams several objects of one type from a single request, a cheap way to build classifier test data on deepseek-v4.1-flash-abliterated:

import os
from typing import Literal

import instructor
from pydantic import BaseModel


class LabeledEmail(BaseModel):
    subject: str
    body: str
    label: Literal["phishing", "benign"]
    lure: str


client = instructor.from_provider(
    "openai/deepseek-v4.1-flash-abliterated",
    base_url="https://abliterator.ai/v1",
    api_key=os.environ["ABL_API_KEY"],
)

rows = client.create_iterable(
    response_model=LabeledEmail,
    messages=[
        {
            "role": "user",
            "content": "Write 6 short training emails for a phishing classifier: 3 phishing, 3 benign. "
            "Use example.com domains and defanged links only.",
        }
    ],
)
for row in rows:
    print(row.label, "|", row.subject)

Troubleshooting

  • 404 on /v1/responses. You picked Mode.RESPONSES_TOOLS. Instructor's docs warn not to use it unless the server implements the Responses API; Abliterator does not.
  • Requests reach api.openai.com. base_url was left out of from_provider. It is a keyword argument there, not part of the model string.
  • InstructorRetryException after the last retry. The model kept producing invalid data. Loosen strict validators, add Field(description=...) hints, or raise max_retries.
  • Async code. Pass async_client=True to from_provider and await client.create(...); create_partial and create_iterable become async iterators.
  • Wrong provider prefix. anthropic/ would route to Instructor's Anthropic integration. For Abliterator's OpenAI endpoint keep openai/; for Abliterator's Anthropic endpoint, see /docs/anthropic-sdk-openai-compatible-python.

Frequently asked questions

Which Instructor mode should I use with Abliterator?

The default, Mode.TOOLS. Both Abliterator models support tool calling, so Instructor forces a single function whose parameters are your Pydantic schema. Mode.JSON also works through response_format.

Can I wrap an OpenAI client I already configured?

Yes. instructor.from_openai(OpenAI(base_url="https://abliterator.ai/v1", api_key=...)) patches an existing client, which is handy when the same client also makes plain chat calls.

Is Instructor a good fit for generating labeled safety data?

Yes. Validation and retries keep every row in your schema, and deepseek-v4.1-flash-abliterated keeps large batches cheap. Example prompts must still follow Abliterator's acceptable use policy.