Skip to content

Support Array Type for Tool Calling Function#1043

Merged
sayanshaw24 merged 1 commit intomainfrom
sayanshaw/func-type-array
Apr 7, 2026
Merged

Support Array Type for Tool Calling Function#1043
sayanshaw24 merged 1 commit intomainfrom
sayanshaw/func-type-array

Conversation

@sayanshaw24
Copy link
Copy Markdown
Collaborator

@sayanshaw24 sayanshaw24 commented Apr 7, 2026

Summary

Fixes a crash in ConvertParameters when a tool function property's "type" field is a JSON array (e.g. ["string", "null"]) instead of a plain string.

Per the OpenAI function calling spec, strict mode requires all fields to be marked as required, and optional fields are denoted by adding "null" as a type option — resulting in "type": ["string", "null"] rather than "type": "string".

Previously, ConvertParameters unconditionally did std::string type = prop_schema["type"], which throws json.exception.type_error.302 when the value is an array. This caused a 500 error in downstream consumers like Foundry Local.

Changes

shared/api/chat_template.cc

  • Updated ConvertParameters to handle "type" as:
    • string — normalized as before ("string""str", others as-is)
    • array — extracts the first non-"null" type from the array and normalizes it
    • any other JSON value — passed through as-is (safety net for unexpected schemas)

test/pp_api_test/test_tokenizer_chat.cc

  • Added Qwen2_5_ChatTemplateWithOAIFunctionTypeArrayType test that uses "type": ["string", "null"] on a property, verifying it normalizes correctly without crashing.

Validation

  • Validated unit test in ORT Extensions
  • Tested e2e with ORT GenAI using phi-4 mini and deepseek r1 distill qwen-1.5b

Fixes

@sayanshaw24 sayanshaw24 marked this pull request as ready for review April 7, 2026 18:34
@sayanshaw24 sayanshaw24 requested a review from a team as a code owner April 7, 2026 18:34
@sayanshaw24 sayanshaw24 enabled auto-merge (squash) April 7, 2026 18:34
@sayanshaw24 sayanshaw24 merged commit 7b9699c into main Apr 7, 2026
38 checks passed
@sayanshaw24 sayanshaw24 deleted the sayanshaw/func-type-array branch April 7, 2026 21:20
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.

2 participants