Define structured outputs using regular expressions to match specific response patterns.
Prompt Example:
{
"prompt": "Extract the date from: 'Weather forecast for Manhattan Beach on 2025-06-03'.",
"structured_output": "\\d{4}-\\d{2}-\\d{2}"
}
Expected Response:
"2025-06-03"
Making an API Call
Send structured output requests using Parasail's inference endpoint:
from openai import OpenAI
# Configure the OpenAI client to point at the Parasail-compatible endpoint
client = OpenAI(
base_url="https://api.parasail.ai/v1", # Parasail OpenAI‑compatible server
api_key="YOUR_API_KEY",
)
# Build and send the request with an OpenAI‑style guided_json parameter
completion = client.chat.completions.create(
model="parasail-qwen3-32b",
messages=[
{
"role": "user",
"content": "What's the weather like in Manhattan Beach on 2025-06-03?",
}
],
extra_body={
"guided_json": {
"type": "object",
"properties": {
"location": {"type": "string"},
"date": {"type": "string", "format": "date"},
},
"required": ["location", "date"],
}
},
)
# The response is already validated by guided decoding to match the schema
print(completion.choices[0].message.content)
Using: parasail-qwen3-32b (to enable thinking, remove /no_think in the prompt to remove thinking)
Input:
/no_think
{
"prompt": "Extract the date from: 'Weather forecast for Manhattan Beach on 2025-06-03'.",
"structured_output": "\\d{4}-\\d{2}-\\d{2}"
}
Output:
The extracted date is: **2025-06-03**.
Parasail Structured Output — 5-Minute Quick-Start
Perfect for someone who just wants to see it work once before reading the details.
Prerequisites
bashCopyEditpip install openai # Parasail is OpenAI-compatible
export PARASAIL_API_KEY="sk-..." # paste your key
One-file demo
Save this as structured_demo.py:
pythonCopyEditimport openai, json
openai.api_key = "sk-..." # or rely on the env-var
openai.api_base = "https://api.parasail.io/v1"
# Ask a question and force the model to answer in JSON
schema = {
"type": "object",
"properties": {
"capital": {"type": "string"},
"country": {"type": "string"}
},
"required": ["capital", "country"],
"additionalProperties": False
}
resp = openai.ChatCompletion.create(
model="parasail-qwen3-32b", # any listed compatible model
messages=[{"role": "user",
"content": "What is the capital of France?"}],
structured_output=schema # <—— the only new field
)
data = resp.choices[0].message.content # already valid JSON
print(json.dumps(json.loads(data), indent=2))