Skip to main content
When utilizing language models within a lengthy process, chain, or pipeline, it is often necessary for the outputs to adhere to a specific structured format. Structured output allows you to enforce predictable formats in model responses. Instead of free-form text, you can guide the model to return JSON objects, schemas, or other structured data that is easy to parse and integrate into applications. We offer a reliable method to obtain structured output in your desired format. Our system includes a built-in mode for JSON output. It lets you define schemas using tools like Pydantic or Zod to enforce data types, constraints, and structure.
Structured Output Example
Document Parsing Example

Use Cases of Structured Output

📄 Document Parsing

Extract and organize content from PDFs, Word files, and other unstructured documents into usable data.

🔎 Entity Extraction

Identify and capture names, dates, amounts, and other key entities from raw text with precision.

📊 Report Generation

Automatically generate structured reports from language model outputs for analytics and insights.

📝 Resume Creation

Transform plain text into professional resumes or structured job application documents.

For JSON mode, it is essential to explicitly instruct the model in your prompt to output JSON and specify the desired format.Custom structured outputs are more reliable and are recommended whenever possible. However, it is still advisable to iterate on your prompts. Use JSON mode when more flexibility in the output is required while maintaining a JSON structure, and customize it if you want to enforce a clearer format to improve reliability.

Why Use Structured Output?

  • Ensure consistent responses
  • Prevent parsing errors from free-form text
  • Enable integrations with APIs, databases, or other systems
  • Make automation workflows more reliable

Sending Structured Output Request in Pawa AI.

Sending request in Pawa AI you simply state your desired output format, for now the default is in JSON mode. You request the model to return the request in the specific JSON format you described in response_format parameter.

JSON Output

You can specify a response_format when calling the model to enforce a JSON schema.

Supported Schemas

For structured output, the following schema types are supported:
  • string
  • number
  • integer
  • float
  • object
  • array
  • boolean
  • enum
  • anyOf

Example: Resume Information Extraction with Structured Outputs

A common use case for Structured Outputs is parsing resumes. Resumes contain structured data such as a candidate’s name, contact details, education, and work history — but extracting this data from raw text can be error-prone. Structured Outputs ensure that the extracted data always matches a predefined schema.

Step 1: Defining the Schema

from typing import List
from datetime import date
from pydantic import BaseModel, Field

class Education(BaseModel):
    institution: str = Field(description="Name of the institution")
    degree: str = Field(description="Degree obtained")
    graduation_year: int = Field(description="Year of graduation")

class Experience(BaseModel):
    company: str = Field(description="Company name")
    role: str = Field(description="Job title or role")
    start_date: date = Field(description="Job start date")
    end_date: date = Field(description="Job end date")
    responsibilities: List[str] = Field(description="List of key responsibilities")

class Resume(BaseModel):
    full_name: str = Field(description="Candidate's full name")
    email: str = Field(description="Candidate's email address")
    phone: str = Field(description="Candidate's phone number")
    education: List[Education] = Field(description="List of education records")
    experience: List[Experience] = Field(description="List of professional experiences")
    skills: List[str] = Field(description="List of candidate's skills")

Step 2: System Prompt

The system prompt instructs the model to extract structured resume data.
Given a raw resume, carefully analyze the text and extract the relevant data into JSON format.
Example Resume Text
Name: Jane Doe
Email: jane.doe@example.com
Phone: +255 688067709

Education:
- B.Sc. Computer Science, UDSM, 2020

Experience:
- Software Engineer at TechCorp (Jan 2021 – Dec 2023)
  Responsibilities: Built APIs, Managed cloud infrastructure

Skills:
Python, JavaScript, AWS, Docker

Step 3: Example API Request to Pawa AI

POST https://api.pawa-ai.com/v1/chat/request
Content-Type: application/json

{
  "model": "pawa-v1-ember-20240924",
  "messages": [
    {
      "role": "system",
      "content": [
        { "type": "text", "text": "You are an AI assistant that extracts resume information into structured JSON." }
      ]
    },
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Here is a resume: Name: Jane Doe, Email: jane.doe@example.com, Phone: +1 555-123-4567, Education: B.Sc. Computer Science, MIT, 2020, Experience: Software Engineer at TechCorp (Jan 2021 – Dec 2023), Skills: Python, JavaScript, AWS, Docker" }
      ]
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "resume_schema",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "full_name": { "type": "string" },
          "email": { "type": "string" },
          "phone": { "type": "string" },
          "education": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "institution": { "type": "string" },
                "degree": { "type": "string" },
                "graduation_year": { "type": "integer" }
              },
              "required": ["institution", "degree", "graduation_year"]
            }
          },
          "experience": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "company": { "type": "string" },
                "role": { "type": "string" },
                "start_date": { "type": "string", "format": "date" },
                "end_date": { "type": "string", "format": "date" },
                "responsibilities": {
                  "type": "array",
                  "items": { "type": "string" }
                }
              },
              "required": ["company", "role", "start_date", "end_date"]
            }
          },
          "skills": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "required": ["full_name", "email", "phone", "education", "experience", "skills"],
        "additionalProperties": false
      }
    }
  }
}

Step 4: Example Type-Safe Output

{
  "full_name": "Jane Doe",
  "email": "jane.doe@example.com",
  "phone": "+255 768067709",
  "education": [
    {
      "institution": "UDSM",
      "degree": "B.Sc. Computer Science",
      "graduation_year": 2020
    }
  ],
  "experience": [
    {
      "company": "TechCorp",
      "role": "Software Engineer",
      "start_date": "2021-01-01",
      "end_date": "2023-12-31",
      "responsibilities": ["Built APIs", "Managed cloud infrastructure"]
    }
  ],
  "skills": ["Python", "JavaScript", "AWS", "Docker"]
}

This shows how Pawa AI can enforce schemas to reliably extract structured resume data.
I