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