Repository navigation
Commit e68f977
authored
Python: Build an array schema for variadic tuple parameters (#14692)
### Motivation and Context
`KernelJsonSchemaBuilder` treats `tuple[int, ...]` as a two-item tuple
whose second item is the `Ellipsis`, so a function parameter typed that
way gets this schema:
```json
{"type": "array", "items": [{"type": "integer"}, {"type": "object"}]}
```
The model is told the argument is exactly one integer followed by an
object, instead of a list of integers.
### Description
When the tuple's arguments are `(X, Ellipsis)`, build `{"type": "array",
"items": <schema of X>}`, the same as `list[X]`. Fixed-length tuples
like `tuple[int, str]` keep their per-position `items`. Added tests for
`tuple[int, ...]` and `Optional[tuple[str, ...]]`; both fail on main.
### Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄1 parent 1ae2a39 commit e68f977
2 files changed
Lines changed: 16 additions & 2 deletions
File tree
- python
- semantic_kernel/schema
- tests/unit/schema
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
207 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
244 | 254 | | |
245 | 255 | | |
246 | 256 | | |
| |||
0 commit comments