Skip to content

Propagate invalid tool descriptor errors in OpenResponses ToolChoice decoding - #444

Merged
mattt merged 1 commit into
huggingface:mainfrom
Pybsama:fix-open-responses-tool-descriptor-decoding
Dec 1, 2026
Merged

mattt merged 1 commit into
huggingface:mainfrom
Pybsama:fix-open-responses-tool-descriptor-decoding

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix OpenResponsesLanguageModel.CustomGenerationOptions.ToolChoice.decodeToolDescriptorArray (Sources/AnyLanguageModel/Models/OpenResponsesLanguageModel.swift) to try decoding plain string entries before opening a nested keyed container, without catching and swallowing descriptor decoding errors.
  • Previously, calling arr.nestedContainer(keyedBy:) advanced arr's index before checking type == "function" and decoding name. Any DecodingError thrown inside the do block (such as an unsupported descriptor type or missing name) was swallowed by the catch block, which then called arr.decode(String.self) on the next element — either silently accepting a trailing string entry or failing with an unrelated valueNotFound ("Unkeyed container is at end.") error.
  • Add toolChoiceAllowedToolsRejectsInvalidDescriptors() in Tests/AnyLanguageModelTests/CustomGenerationOptionsTests.swift.

Verification

  • swift format lint --strict --recursive . (Swift 6.3.3): passed
  • swift test --disable-index-store --filter "toolChoiceAllowedTools": failed pre-fix (silently decoded ["fallback"]) -> 2/2 passed post-fix
  • swift test --skip-build --disable-index-store --skip OllamaLanguageModelTests: 1,104/1,104 passed across 113 suites

@mattt
mattt merged commit c0f6b53 into huggingface:main Dec 1, 2026
14 checks passed
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