OPENAI PLATFORM · LESSON 219 OF 278

Structured Outputs and Function Calling

Use schemas and function tools to connect models to deterministic application logic.

What you will learn

Use schemas and function tools to connect models to deterministic application logic.

In simple words

Structured outputs help applications receive predictable data, while function calling lets the model request approved actions. Schemas improve reliability but do not replace server-side validation or authorization.

Visual explanation: Structured Outputs and Function Calling

Follow the platform concept from setup through production use.

WATCH THE IDEA

Structured Outputs and Function Calling

Playing
Model intentSchema + authorizationSafe action
  1. 1Observe: Model intent
  2. 2Transformation: Schema + authorization
  3. 3Outcome: Safe action

Observe: Model intent. Follow the platform concept from setup through production use.

The diagram highlights Model intent, Schema + authorization, Safe action. Use the labels to trace the main relationship from left to right.

Real-world example: Operational AI decision

A team applies structured outputs and function calling to a real business workflow.

What the team decides: Let the model propose actions; let trusted code decide whether they may execute.

Risk to avoid: A strong technical concept still needs measurement, safeguards, and ownership in production.

Technical explanation

Structured outputs help applications receive predictable data, while function calling lets the model request approved actions. Schemas improve reliability but do not replace server-side validation or authorization.

Python and implementation examples

Use these examples to connect the concept to working code. Package-based examples assume the named library is installed in your own environment.

Validate tool arguments before execution

python
from pydantic import BaseModel, Field

class TicketLookup(BaseModel):
    ticket_id: str = Field(min_length=3, max_length=64)

def execute_lookup(raw_args: dict, current_user: dict):
    args = TicketLookup.model_validate(raw_args)

    if not current_user.get("can_read_tickets"):
        raise PermissionError("User is not authorized to read tickets")

    return {"ticket_id": args.ticket_id, "status": "open"}

A model can propose a tool call, but trusted application code should validate the schema and authorize the current user before doing real work.

Common misconception

This concept is not a guarantee of a correct outcome by itself. Its value depends on suitable evidence, careful implementation, and evaluation against the real task.

QUICK QUIZ

Where should authorization be enforced for a model-proposed function call?

Practical application

Let the model propose actions; let trusted code decide whether they may execute.

Key takeaway

Let the model propose actions; let trusted code decide whether they may execute.

Next concept

Continue with OpenAI Built-in Tools.

Engineering view

Let the model propose actions; let trusted code decide whether they may execute.

Internals view

Use schemas and function tools to connect models to deterministic application logic. Structured outputs help applications receive predictable data, while function calling lets the model request approved actions. Schemas improve reliability but do not replace server-side validation or authorization.

Architecture view

Consider the Model intent → Schema + authorization → Safe action flow, and make the system's inputs, checks, and outcomes explicit.

Was this lesson helpful?

Lesson discussion

Comments are reviewed before publication. Keep discussion focused on learning and do not post private information.

Loading discussion…

Your quiz answer and current lesson are saved on this device. Sign in to explore account-backed learning features.

Content version 1 · Last reviewed 2026-10-16