Capabilities
Structured outputs
When you need a machine-readable answer rather than prose — extracting fields, classifying, building an API response — structured outputs make the model return valid JSON every time, so there's no fragile string-parsing on your end. Pendra enforces this with a grammar at generation time, not just a prompt instruction, so the output is guaranteed to parse.
JSON mode
Set response_format to
{ "type": "json_object" } and the reply is guaranteed to
be syntactically valid JSON. Use this when you want JSON but don't need a
specific shape — describe the fields you want in your prompt.
JSON Schema
For a guaranteed shape, pass
{ "type": "json_schema", "json_schema": { ... } }. The
model is constrained to produce output matching your schema — the right
keys, the right types — so you can deserialise straight into your own
types.
If response_format is malformed — a type other
than text, json_object, or
json_schema, or { "type": "json_schema" }
without its json_schema object — the request is rejected with
a 422 before it runs, so a bad constraint fails fast instead
of quietly returning unconstrained text.
from pendra import Pendra
client = Pendra()
response = client.chat.completions.create(
model="qwen3.6:27b",
messages=[{"role": "user", "content": "Extract the name and age from: Sara is 34."}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "person",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
},
},
},
},
)
print(response.choices[0].message.content) # {"name": "Sara", "age": 34} { "name": "Sara", "age": 34 }