Skip to content

Accept stringified primitives in Generable conversions - #185

Closed
james-333i wants to merge 143 commits into
huggingface:mainfrom
james-333i:fix/tool-argument-string-coercion
Closed

Accept stringified primitives in Generable conversions#185
james-333i wants to merge 143 commits into
huggingface:mainfrom
james-333i:fix/tool-argument-string-coercion

Conversation

@james-333i

Copy link
Copy Markdown

Some chat templates stringify every tool-call argument value, so models emit {"count": "5"} where the schema declares an integer. The strict kind checks in the primitive Generable initializers then throw typeMismatch, which makes any non-String tool argument unusable on those backends.

Accept string content in the Bool, Int, Float, Double, and Decimal initializers when it parses unambiguously as the target type. Native kinds decode exactly as before, and unparseable strings still throw typeMismatch. Integer parsing accepts only whole-number values.

mattt and others added 30 commits October 7, 2025 11:25
* Core ML: apply chat template

* Cache compiled models

* Update Core ML respond and streamResponse implementations

* Require Core ML models to be compiled

* Add chat template and tool spec handlers to CoreMLLanguageModel initializer

* Add documentation comments to CoreMLLanguageModel

* Throw specialized error in CoreMLLanguageModel initializer

* Rename variable

* Set property type to any Tokenizer

* Re-add #if CoreML conditional

---------

Co-authored-by: Mattt Zmuda <mattt@me.com>
mattt and others added 26 commits February 11, 2026 07:17
* Implement guided generation for OllamaLanguageModel

* Add test coverage for Ollama guided generation

* Incorporate feedback from review
* Restructure usage section of README

* Create separate Providers section and reorganize subheadings

* Remove now outdated note about Ollama not supporting guided generation

* Bump version to 0.7.0
…huggingface#129)

* Filter injected tool definitions by includesSchemaInInstructions

* Fixed synthesized Foundation Models transcript instructions to include tool definitions

* Add test coverage for tool definitions in instructions

* Fix race in response streaming tests
…huggingface#126)

* Simplify LanguageModelSession state management

- Fix race condition when streaming responses.

* Replace OSAllocatedUnfairLock with Locked

* Re-enable observation for LanguageModelSession.isResponding and transcript

* Replace os_unfair_lock and pthread_mutex_t with NSLock
* Move Locked to new Shared subdirectory

* Rename Locked.access to Locked.withLock

* Add concise documentation comments to Locked

* Move StructuredGeneration to Shared directory

* Adopt Locked in MLXLanguageModel

* Adopt Locked in StructuredGeneration

* Don't shadow inFlight in closure

* Replace Important with Note

* Don't shadow state in closure
…e#125)

* Fix format mismatch in OpenAI responses API

* Rewrite expressions to improve clarity

* Add unit tests for OpenAI tool calling formatting

---------

Co-authored-by: Mattt Zmuda <mattt@me.com>
* Expand test coverage for ToolExecutionDelegate

* Add tests for Character extensions

* Add tests for generated content convertibility

* Add tests for dynamic schema generation

* Add tests for instructions

* Add tests for generation guides

* Add tests for feedback

* Make defaultInstructionsAndPromptRepresentationsUseJSONString resilient to guardrail violations

* Add tests for JSONDecoder extension

* Add tests for prompt

* Add tests for transcript

* Add tests for URLSession extension

* Make defaultInstructionsAndPromptRepresentationsUseJSONString resilient to key reordering
* Add UnavailableReason for MLXLanguageModel

* Distinguish between not loaded and load failure

* Refactor model state / context caching

* Use removeFromCache to explicitly unload models when checking availability
… race (huggingface#134)

* Serialize Linux URLSession request paths to mitigate _MultiHandle race

* Incorporate feedback from review

* Replace withLock instance method with top-level withLinuxRequestLock helper

* Fix Linux compiler bug around generic returning lock helper

* More workarounds for Linux compiler bugs

* Incorporate feedback from review

* AsyncHTTPClient support for linux (huggingface#143)

* deps: add trait-based import of AsyncHTTPClient

* feat: implement transparent AsyncHTTPClient wrapper

* deps: conditionally include trait in EventSource

* Increase HTTP request timeout from 60 to 180 seconds

---------

Co-authored-by: Leonhard Solbach <49833472+KotlinFactory@users.noreply.github.com>

* Incorporate feedback from review

* swift format -i -r .

---------

Co-authored-by: Jonas Stoehr <jonass@dev.jsje.de>
Co-authored-by: Leonhard Solbach <49833472+KotlinFactory@users.noreply.github.com>
…ce#147)

* Implement safe MLX KV reuse with scoped GPU cache eviction

* Incorporate feedback from review

* Incorporate feedback from review

* Incorporate feedback from second round of review
…ce#148)

* Update CI workflow to run Linux directly on container

* Attempt to resolve hashFiles issue

* Add --traits AsyncHTTPClient to test matrix

* Resolve warning about try with non-throwing expression

* Temporarily disable failing case in CI matrix
* Add additionalContext support to MLXLanguageModel

* Fix merge conflict resolution

* Incorporate feedback from review

* Add userInputProcessing property to MLX custom generation options

* Group KV cache generation options into struct

* Improve ergnomics of resize processor at call site

* Fix compiler errors due to JSONValue ambiguity

* Update expectation for MLX image processing test

* Incorporate feedback from review

---------

Co-authored-by: Mattt Zmuda <mattt@me.com>
* Update README

* Switch to Apache 2 license

* Update code examples to use from: instead of branch: main
* Bump mlx-swift-lm to 3.x (3.31.3)

* Less comments

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

---------

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
* Temporarily remove Swift 6.1 from the CI matrix.

mlx-swift-lm 3.x upgraded Swift version, which fails to compile with
strict concurrency for SDKs earlier than 26.

An alternative would be to test the "MLX" trait separately on just Xcode
26, and keep the full matrix for the rest of traits.

* Use NIOCore to restore Linux compatibility.

Graph resolution changed after the bump to mlx-swift-lm 3 and
it looks like NIOFoundationCompat is no longer there.
* Restore CI matrix

* Temporarily disable cache in CI

* Upgrade swift-syntax for mlx-swift-lm 3.31.4 to be resolved
* Add the thinking content type.

Sonnet 5 would start a “thinking” content block that was not properly recognized. This adds support for decoding the block.

Signed-off-by: Taylor Lineman <git@actuallytaylor.com>

* Update Sources/AnyLanguageModel/Models/AnthropicLanguageModel.swift

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

---------

Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
In preparation for Dependabot
* chore: enable Dependabot weekly GitHub Actions bumps

* Monthly updates

---------

Co-authored-by: hf-dependantbot-rollout[bot] <285970069+hf-dependantbot-rollout[bot]@users.noreply.github.com>
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Bumps the actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [actions/cache](https://github.com/actions/cache).


Updates `actions/checkout` from 6.0.3 to 7.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@df4cb1c...9c091bb)

Updates `actions/cache` from 5.1.0 to 6.1.0
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](actions/cache@caa2961...55cc834)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/cache
  dependency-version: 6.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Some chat templates stringify every tool-call argument value, so models
emit {"count": "5"} where the schema declares an integer. The strict
kind checks in the primitive Generable initializers then throw
typeMismatch, which makes any non-String tool argument unusable on
those backends.

Accept string content in the Bool, Int, Float, Double, and Decimal
initializers when it parses unambiguously as the target type. Native
kinds decode exactly as before, and unparseable strings still throw
typeMismatch. Integer parsing accepts only whole-number values.
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.