apple: number schema with both minimum and maximum drops the minimum (DynamicGenerationSchema early return)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react-native, swift, typescript
調査の方向性
バグは ios/AppleLLMImpl.swift の数値スキーマ変換部分(449〜462行目付近)にあります。maximum の分岐が、minimum のチェックが実行される前に return しています。周囲の関数を読んでから、minimum 1 と maximum 90 を宣言した整数スキーマで再現してください。両方の境界が生成ガイドに適用され、排他的境界の分岐も同じ方法で修正され、組み合わせのケースをテストが網羅していれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
In @react-native-ai/apple 0.12.0, a JSON Schema number or integer that declares both minimum and maximum loses its minimum when converted to a DynamicGenerationSchema. The model can then generate values below the declared lower bound, e.g. 0 or a negative for a field declared minimum: 1, maximum: 90.
Where
ios/AppleLLMImpl.swift (v0.12.0), around lines 449–462:
if let maximum = schemaDict["maximum"] as? Double {
if type == "integer" {
return DynamicGenerationSchema(type: Int.self, guides: [GenerationGuide.maximum(Int(maximum))])
} else {
return DynamicGenerationSchema(type: Double.self, guides: [GenerationGuide.maximum(maximum)])
}
}
if let minimum = schemaDict["minimum"] as? Double { // never reached when "maximum" is present
...
}
The maximum branch returns early, so the minimum branch is only reached when there is no maximum. The exclusiveMaximum / exclusiveMinimum branches below have the same early-return shape.
Repro
A tool with this parameter schema (e.g. from Zod z.number().int().min(1).max(90)):
{ "type": "object", "properties": { "days": { "type": "integer", "minimum": 1, "maximum": 90 } }, "required": ["days"] }
- Expected: a generation guide constraining
daysto 1…90. - Actual: only
maximum(90)is applied, and the model can emitdays: 0or a negative.
Suggested fix
Collect all bound guides for the property and pass them together, instead of returning on the first one. For example:
var guides: [GenerationGuide<Int>] = []
if let min = schemaDict["minimum"] as? Double { guides.append(.minimum(Int(min))) }
if let max = schemaDict["maximum"] as? Double { guides.append(.maximum(Int(max))) }
// same for exclusive bounds (+1 / -1), and the Double variant
if !guides.isEmpty { return DynamicGenerationSchema(type: Int.self, guides: guides) }
Or use a single range guide when both bounds are present.
Impact / workaround
We now validate tool arguments ourselves before executing, so out-of-range values are rejected. That still wastes a model turn, though, and anyone relying on the schema alone gets invalid arguments.
Thanks for the library!
- 主要言語
- TypeScript
- スター
- 1.4k
- フォーク
- 64
- 平均マージ
- 11時間 24分
- マージ済み PR(30日)
- 91
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
callstackincubator/ai のほかの issue
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
callstackincubator/ai#366 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
callstackincubator/ai#365 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Blocked enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 30/100
callstackincubator/ai#364 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Blocked enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
callstackincubator/ai#363 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Blocked enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
callstackincubator/ai#362 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
callstackincubator/ai の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
cursor/community-plugins#583 ·
メンテナーはふだん 1 日以内に返信
-
afk-ok importer size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
enorm-labs/event-junkie#5404 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Wavvon/Wavvon-clients#493 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
answerLoops/answerLoops#679 ·
メンテナーはふだん 1 日以内に返信