apple: number schema with both minimum and maximum drops the minimum (DynamicGenerationSchema early return)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react-native, swift, typescript
- Domain
- machine-learning, mobile
Research direction
The bug is in the number-schema conversion in ios/AppleLLMImpl.swift (around lines 449–462), where the maximum branch returns before the minimum check runs. Read the surrounding function, then reproduce with an integer schema declaring minimum 1 and maximum 90. Done means both bounds are applied to the generation guides, the exclusive-bound branches are fixed the same way, and a test covers the combined case.
Written by the indexing model from the issue text.
Description
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!
- Dominant language
- TypeScript
- Stars
- 1.4k
- Forks
- 64
- Avg merge
- 11h 8m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from callstackincubator/ai
-
feat(android): add ml kit task apis and context cachingPossibly taken A pull request linked to this issue is open or already merged. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 20/100
callstackincubator/ai#366 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 20/100
callstackincubator/ai#365 · 2 comments ·
-
Blocked enhancement
Difficulty 3/5 1-2 days Newbie friendliness 30/100
callstackincubator/ai#364 · 1 comment ·
-
feat(android): add streamed and live transcription with word timingsPossibly taken A pull request linked to this issue is open or already merged. OpenBlocked enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
callstackincubator/ai#363 · 1 comment ·
-
Blocked enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
callstackincubator/ai#362 · 1 comment ·
All issues in callstackincubator/ai
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
melgarafael/DeskcommCRM#5614 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 76/100
slackapi/slack-health-score#253 ·
Maintainers usually reply within 1 day
-
feature needs triage site
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
owid/owid-grapher#8019 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
simstudioai/sim#10710 ·
Maintainers usually reply within 1 day
-
via-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day