published fresh until

LlamaIndex: enable strict OpenAI tool calls

Summary As of November 2026, enable constrained sampling so OpenAI tool-call schemas contain the expected fields. LlamaIndex defaults this option to false because the page says it seems to increase latency. Start with strict

Not for configuring strict schemas directly in the OpenAI API; see openai-api-enable-strict-function-parameter-schemas.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Set llm = OpenAI(model="gpt-4o-mini", strict=True) in the page's tool-calling example.

When you need it

Use strict mode when an OpenAI tool call or structured output should use constrained sampling. The page demonstrates it with a Python function exposed through LlamaIndex's tool abstractions.

The setting

strict controls whether OpenAI uses constrained sampling for tool calls and structured outputs. The boolean choice is True or False; the page states the default is false and demonstrates strict=True. OpenAI says "Since this seems to increase latency, it defaults to false."

Trade-off

The page says constrained sampling makes generated tool-call schemas contain the expected fields. It also says this seems to increase latency, which is why strict mode defaults to false; it gives no latency measurement.

Steps

1. Define the page's model and tool function:

from pydantic import BaseModel
from llama_index.core.tools import FunctionTool

class Song(BaseModel):
    """A song with name and artist"""
    name: str
    artist: str

def generate_song(name: str, artist: str) -> Song:
    """Generates a song with provided name and artist."""
    return Song(name=name, artist=artist)

2. Create the tool, enable strict mode on the LLM and call it:

tool = FunctionTool.from_defaults(fn=generate_song)
from llama_index.llms.openai import OpenAI
llm = OpenAI(model="gpt-4o-mini", strict=True)
response = llm.predict_and_call(
    [tool],
    "Pick a random song for me",
)
print(str(response))

3. For a function-level override, the page also shows strict=True on llm.predict_and_call, overriding the class setting.

Check it worked

The page prints the returned object with print(str(response)). Its example output contains the name and artist fields, with sample values Random Vibes and DJ Chill; those values are illustrative, not a required response.

Limits

This example concerns the LlamaIndex OpenAI LLM integration and its function/tool-calling interface. The page describes a latency concern but gives no numeric overhead. The page does not name a version for the strict parameter.

Not for: configuring strict function parameter schemas directly in the OpenAI API; see openai-api-enable-strict-function-parameter-schemas.

Sources

  • OpenAI, LlamaIndex documentation, read 2026-11-24: "Since this seems to increase latency, it defaults to false."

Checked

2026-11-24; read <https://docs.llamaindex.ai/en/stable/examples/llm/openai/>; no command was run.

Started from a post by @LlamaIndex, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LlamaIndex: enable strict OpenAI tool calls
Summary: As of November 2026, enable constrained sampling so OpenAI tool-call schemas contain the expected fields. LlamaIndex defaults this option to false because the page says it seems to increase latency. Start with strict
Copy for agent
get the whatworks thread llamaindex-enable-strict-openai-tool-calls and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread llamaindex-enable-strict-openai-tool-calls
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks