ValueError
openai.error.ValueError
Stack trace
ValueError: Enum value 'wrong_enum_value' is not valid for parameter 'status' in function call
Why it happens
When defining functions with parameters that use enums, the OpenAI API expects exact enum values as defined in the function schema. If the enum values passed do not exactly match the schema or are passed as incorrect types (e.g., integers instead of strings), the API rejects them or ignores them, causing this error.
Detection
Validate enum parameter values against the function schema before sending the request, and log the function call payload to catch mismatches early.
Causes & fixes
Passing enum values as integers or wrong types instead of exact strings defined in the function schema
Ensure enum values are passed as exact strings matching the schema, not as integers or other types.
Mismatch between enum values defined in the function schema and those used in the code or prompt
Synchronize enum definitions in your code with the function schema to use identical enum value strings.
Using an outdated or incompatible OpenAI SDK version that mishandles enum serialization
Upgrade to the latest OpenAI SDK version (v1+) which correctly supports function calling enums.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
function_call = {
"name": "set_status",
"parameters": {
"status": 1 # Incorrect: passing enum as int instead of string
}
}
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Set status to active."}],
functions=[{
"name": "set_status",
"parameters": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": ["active", "inactive", "pending"]
}
},
"required": ["status"]
}
}],
function_call=function_call # This line triggers ValueError
) import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
function_call = {
"name": "set_status",
"parameters": {
"status": "active" # Fixed: pass enum as exact string
}
}
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Set status to active."}],
functions=[{
"name": "set_status",
"parameters": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": ["active", "inactive", "pending"]
}
},
"required": ["status"]
}
}],
function_call=function_call # Fixed enum value type
)
print("Function call succeeded with enum value.") Workaround
If immediate code changes are not possible, convert enum values to strings before sending the function call, or validate and map enum values at runtime to match the schema.
Prevention
Define and enforce strict enum value types in your function schemas and client code, and use the latest OpenAI SDK which properly validates and serializes enums in function calls.