API reference
Structured outputs
Get JSON from Abliterator's models with response_format json_object or json_schema, or Anthropic output_config.format, and validate every response in your code.
Abliterator passes response_format (json_object or json_schema) to the model, and output_config.format in the Messages API. The serving engine constrains output to your schema, but always validate the result in code before you use it.
Two modes
response_format |
What you get |
|---|---|
{"type": "json_object"} |
Valid JSON. You describe the shape in the prompt |
{"type": "json_schema", "json_schema": {"name": "...", "schema": {...}}} |
JSON shaped by your schema |
Abliterator forwards response_format to the model unchanged. The serving engine uses it to constrain generation. How closely the output follows a complex schema still depends on the model and the prompt, so treat the schema as strong guidance, not a guarantee: parse and validate every response.
JSON schema with validation (Python)
This example extracts structured fields from a vulnerability report and validates them with Pydantic. Install openai and pydantic.
import json
import os
from openai import OpenAI
from pydantic import BaseModel, Field, ValidationError
client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
class Finding(BaseModel):
title: str
severity: str = Field(pattern="^(low|medium|high|critical)$")
cwe: str = Field(pattern=r"^CWE-\d+$")
affected_endpoint: str
remediation: str
REPORT = """The /api/v2/export endpoint builds a SQL query by concatenating the
'sort' query parameter. Supplying a crafted value changes the ORDER BY clause and
allows boolean-based inference of other columns."""
schema = Finding.model_json_schema()
for attempt in range(3):
response = client.chat.completions.create(
model="deepseek-v4.1-flash-abliterated",
max_tokens=4096,
response_format={"type": "json_schema", "json_schema": {"name": "finding", "schema": schema}},
messages=[
{"role": "system", "content": "Extract one security finding from the report. Reply with JSON only."},
{"role": "user", "content": REPORT},
],
)
try:
finding = Finding.model_validate(json.loads(response.choices[0].message.content))
break
except (json.JSONDecodeError, ValidationError) as err:
print(f"attempt {attempt + 1} failed validation: {err}")
else:
raise RuntimeError("no valid output after 3 attempts")
print(finding)
JSON mode (Node)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const response = await client.chat.completions.create({
model: "deepseek-v4.1-flash-abliterated",
max_tokens: 2048,
response_format: { type: "json_object" },
messages: [
{
role: "system",
content: 'Classify the message. Reply with JSON: {"label": "phishing" | "spam" | "benign", "reasons": string[]}',
},
{ role: "user", content: "Your mailbox is full. Verify your password at http://mail-support.example.net within 24 hours." },
],
});
let result;
try {
result = JSON.parse(response.choices[0].message.content);
} catch {
throw new Error("model returned invalid JSON");
}
if (!["phishing", "spam", "benign"].includes(result.label) || !Array.isArray(result.reasons)) {
throw new Error("JSON did not match the expected shape");
}
console.log(result);
With json_object, always say "JSON" in the prompt and describe the fields, because the format setting alone does not tell the model what shape you want.
Anthropic Messages format
The Messages API takes the schema in output_config.format:
import json
import os
import anthropic
client = anthropic.Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"])
schema = {
"type": "object",
"properties": {
"label": {"type": "string", "enum": ["phishing", "spam", "benign"]},
"confidence": {"type": "number"},
},
"required": ["label", "confidence"],
"additionalProperties": False,
}
message = client.messages.create(
model="deepseek-v4.1-flash-abliterated",
max_tokens=2048,
messages=[{"role": "user", "content": "Classify: 'Your parcel is held. Pay the 1.99 fee at hxxp://parcel-fee.example to release it.'"}],
extra_body={"output_config": {"format": {"type": "json_schema", "schema": schema}}},
)
text = "".join(block.text for block in message.content if block.type == "text")
print(json.loads(text))
Validate every response
Constrained decoding makes valid JSON very likely, not certain. Plan for failure:
- Parse and validate with Pydantic, Zod,
jsonschemaor similar. Do not pass unvalidated model output to a database, a shell or another system. - Retry on failure a small, fixed number of times, as in the Python example.
- Check
finish_reason.lengthmeans the output was cut off atmax_tokensand the JSON is incomplete. Reasoning counts toward that limit, so give it room or lowerreasoning_effort. - Keep schemas simple. Flat objects with enums and required fields work more reliably than deep nesting,
oneOfand long pattern constraints.
Structured output through tools
Many libraries get structured output by forcing a call to a single tool. That works on deepseek-v4.1-flash-abliterated. On kimi-k3.1-pro-abliterated, a named tool_choice is rejected while reasoning is on (tool_choice 'specified' is incompatible with thinking enabled). Options:
- Use
response_formatwithjson_schemainstead. In LangChain, for example,with_structured_output(..., method="json_schema"). - Send
reasoning_effort: "none"along with the forced tool. - Use deepseek-v4.1-flash-abliterated for extraction steps.
See tool calling.