Skip to content

fix: handle non-string enum values in token counting for structured outputs#7380

Open
SinzoL wants to merge 1 commit intomicrosoft:mainfrom
SinzoL:fix/7201-enum-structured-outputs-deepseek
Open

fix: handle non-string enum values in token counting for structured outputs#7380
SinzoL wants to merge 1 commit intomicrosoft:mainfrom
SinzoL:fix/7201-enum-structured-outputs-deepseek

Conversation

@SinzoL
Copy link

@SinzoL SinzoL commented Mar 13, 2026

The token counting logic for tool schemas assumes enum values are always strings and passes them directly to tiktoken.encode(). When a Pydantic model uses IntEnum or other non-string enum types, this raises a TypeError. Wrap enum values with str() before encoding, matching the pattern already used for other JSON Schema fields like 'type'. Fixes #7201

…utputs

The token counting logic for tool schemas assumes enum values are
always strings and passes them directly to tiktoken.encode(). When a
Pydantic model uses IntEnum or other non-string enum types, this
raises a TypeError because tiktoken only accepts strings.

Wrap enum values with str() before encoding, matching the pattern
already used for other JSON Schema fields like 'type'.

Fixes microsoft#7201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIChatCompletionClient fails with Enum-based Structured Outputs on DeepSeek-Chat

1 participant