Parasail
  • Welcome
  • Serverless
    • Serverless
    • Available Parameters
  • Dedicated
    • Dedicated Endpoints
    • Speeding up Dedicated Models with Speculative Decoding
    • Deploying private models through HuggingFace Repos
    • Dedicated Endpoint Management API
    • Rate Limits and Limitations
    • FP8 Quantization
    • Auto-Scaling
  • Batch
    • Quick start
    • Batch Processing with Private Models
    • Batch file format
    • API Reference
  • Cookbooks
    • Run and Evaluate Any Model
    • Chat Completions
    • RAG
    • Multi-Modal
    • Text-to-Speech with Orpheus TTS models
    • Multimodal GUI Task Agent
    • Tool/Function Calling
    • Structured Output
  • Image Generation and Editing
  • Billing
    • Pricing
    • Billing And Payments
    • Promotions
    • Batch SLA
  • Security and Account Management
    • Data Privacy and Retention
    • Account Management
    • Compliance
  • Resources
    • Silly Tavern Guide
    • Community Engagement
Powered by GitBook
On this page
  • Overview
  • Best Practices
  • Currently Supported Models:
  • Structured Output Formats
  • Making an API Call
  • Examples:
  • Troubleshooting tips:
  1. Cookbooks

Structured Output

Overview

Parasail APIs offer built-in support for structured outputs, enabling easy integration and reliable data parsing.

Best Practices

  • Clearly define your schema in the prompt.

  • Use simple and direct parameters to facilitate predictable responses.

  • Validate responses against your expected schema.

By using structured outputs, Parasail helps developers maintain consistency and integration simplicity across applications.

Currently Supported Models:

Models
Structured Outputs
JSON Schema
Python Object
Regex

parasail-llama-33-70b-fp8

Y

Y

Y

parasail-llama-4-scout-instruct

Y

Y

Y

Y

parasail-llama-4-maverick-instruct-fp8

Y

Y

Y

Y

parasail-qwen3-30b-a3b

Y

Y

Y

parasail-qwen3-235b-a22b

Y

Y

Y

parasail-qwen3-32b

Y

Y

Y

parasail-gemma3-27b-it

Y

Y

Y

Y

parasail-mistral-devstral-small

Y

Y

Y

Y

Structured Output Formats

Parasail supports several structured output formats based on OpenAI specifications:

1. JSON Schema

Define structured responses using JSON schema to ensure clear data contracts.

Prompt Example:

{
  "prompt": "What's the weather like in Manhattan Beach on 2025-06-03?",
  "structured_output": {
    "type": "object",
    "properties": {
      "location": {"type": "string"},
      "date": {"type": "string", "format": "date"}
    },
    "required": ["location", "date"]
  }
}

Expected Response:

{
  "location": "Manhattan Beach",
  "date": "2025-06-03"
}

2. Python Object

Responses structured directly as Python dictionaries for seamless Python integrations.

Prompt Example:

{
  "prompt": "Return the weather info for Manhattan Beach on 2025-06-03.",
  "structured_output": "dict"
}

Expected Response (Model Dependent):

{
  "location": "Manhattan Beach",
  "date": "2025-06-03"
}

3. Regex

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)


Examples:

Using the Parasail Serverless Chat Example:

curl https://api.parasail.io/v1/chat/completions \
 -H "Authorization: Bearer $PARASAIL_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{
       "model": "parasail-qwen3-32b",
       "messages": [{"role":"user","content":"Return today’s date only."}],
       "structured_output":"\\d{4}-\\d{2}-\\d{2}"
     }'

JSON Example:

Using: parasail-qwen3-32b (to enable thinking, remove /no_think in the prompt to remove thinking)

Input:

/no_think
{
"prompt": "What's the weather like in Manhattan Beach on 2025-06-03?",
"structured_output": {
"type": "object",
"properties": {
"location": {"type": "string"},
"date": {"type": "string", "format": "date"}
},
"required": ["location", "date"]
}
}

Output

```json
{
"location": "Manhattan Beach",
"date": "2025-06-03"
}
```

Python Object:

Using: parasail-qwen3-32b (to enable thinking, remove /no_think in the prompt to remove thinking)

Input:

/no_think
{
"prompt": "Return the weather info for Manhattan Beach on 2025-06-03.",
"structured_output": "dict"
}

Output:

```json
{
"location": "Manhattan Beach, CA",
"date": "2025-06-03",
"weather": {
"condition": "Partly Cloudy",
"high_temperature": "72°F",
"low_temperature": "60°F",
"wind": {
"speed": "10 mph",
"direction": "WNW"
},
"precipitation": "0%",
"humidity": "68%",
"uv_index": 5
}
}
```

Regex:

JSON Example:

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.


  1. Prerequisites

    bashCopyEditpip install openai   # Parasail is OpenAI-compatible
    export PARASAIL_API_KEY="sk-..."      # paste your key
  2. 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))
  3. Run it

    bashCopyEditpython structured_demo.py

    Expected output:

    jsonCopyEdit{
      "capital": "Paris",
      "country": "France"
    }
  4. Swap constraints in one line

    Want a date instead? Replace the schema with a regex:

    pythonCopyEditstructured_output = r"\d{4}-\d{2}-\d{2}"   # ISO date

    Want a fixed choice?

    pythonCopyEditstructured_output = ["red", "green", "blue"]


Troubleshooting tips:

Symptom
Likely Cause
Fix

Model ignores constraint

Prompt overshadowed parameter

Put the schema/regex in both your prompt and structured_output.

Response is valid JSON but wrong keys

additionalProperties not set

Add "additionalProperties": false to your schema.

Streaming needed

Large JSON output

Use stream=True – constraints still apply.

PreviousTool/Function CallingNextImage Generation and Editing

Last updated 8 hours ago