Tuple + Array #3443
Answered
by
chrissikora
StefanTerdell
asked this question in
Q&A
Tuple + Array
#3443
|
Hey friends! I'm looking for a way to replicate the following type: type X = [string, boolean, ...number[]]In Json Schema this would be something like this (in +2020 replace {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "number"
}
],
"additionalItems": {
"type": "number"
},
"minItems": 2
}Any ideas? V4 candidate perhaps? |
Answered by
chrissikora
May 7, 2024
Replies: 2 comments
|
Try |
0 replies
Answer selected by
StefanTerdell
|
Worth checking if you convert schemas for tool calling: Zod 4.4.3 emits {"type":"array","prefixItems":[{"type":"string"},{"type":"number"}]} for z.tuple([z.string(), z.number()]) — no minItems, no items: false. So the JSON Schema the model sees accepts [], ["a"] and ["a",1,2], all of which Zod then rejects at runtime, after the provider already approved the call. ArkType and TypeBox both emit the length constraints for the same shape. I found it with schema-parity. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try
z.tuple([ z.string(), z.boolean()]).rest(z.number())