Implementation:Openai Openai python Shared Params Function Definition
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for defining a function signature when using function calling with the OpenAI API, provided by the openai-python SDK.
Description
FunctionDefinition is a TypedDict that defines the schema for a callable function in function calling requests. The only required field is name (alphanumeric with underscores/dashes, max 64 characters). Optional fields include description (used by the model to decide when to call the function), parameters (a JSON Schema object describing the function's arguments), and strict (whether to enforce strict schema adherence using Structured Outputs). This is the shared_params variant used in request/input contexts.
Usage
Import this type when you need to type-annotate function tool definitions for chat completions, assistants, or the Responses API that use function calling.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/shared_params/function_definition.py
Signature
class FunctionDefinition(TypedDict, total=False):
name: Required[str]
description: str
parameters: FunctionParameters
strict: Optional[bool]
Import
from openai.types.shared_params import FunctionDefinition
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The name of the function (a-z, A-Z, 0-9, underscores, dashes; max 64 chars). |
| description | str | No | A description of what the function does, used by the model to choose when and how to call it. |
| parameters | FunctionParameters | No | The function's parameters described as a JSON Schema object. Omitting defines a function with an empty parameter list. |
| strict | Optional[bool] | No | Whether to enable strict schema adherence. When true, the model follows the exact schema. Only a subset of JSON Schema is supported. |
Usage Examples
from openai.types.shared_params import FunctionDefinition
get_weather: FunctionDefinition = {
"name": "get_weather",
"description": "Get the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
},
},
"required": ["location"],
},
"strict": True,
}