Skip to content

fix: remove stale type key from union schemas#80

Merged
jph00 merged 2 commits intoAnswerDotAI:mainfrom
thechandru:fix-union-type-schema
Mar 12, 2026
Merged

fix: remove stale type key from union schemas#80
jph00 merged 2 commits intoAnswerDotAI:mainfrom
thechandru:fix-union-type-schema

Conversation

@thechandru
Copy link

Problem: When using union types with parameterized containers (e.g. list[str] | None), the generated JSON schema includes a conflicting type: object key alongside anyOf, causing LLMs to return stringified arrays instead of proper JSON arrays.

Reproduction:

from toolslm.funccall import get_schema

def f(items: list[str] | None = None):
    "Docstring"
    pass

get_schema(f)['input_schema']['properties']['items']
# {'type': 'object', 'description': '', 'default': None,
#  'anyOf': [{'type': 'array', 'items': {'type': 'string'}}, {'type': 'null'}]}
# 'type': 'object' conflicts with anyOf per JSON Schema spec

Fix: In _process_property, pop the type key when anyOf is present. Per JSON Schema spec, keywords at the same level are ANDed — so type: object alongside anyOf creates a contradictory schema.

After fix:

{'description': '',
 'default': None,
 'anyOf': [{'type': 'array', 'items': {'type': 'string'}}, {'type': 'null'}]}

Verified: Tested end-to-end with Lisette — Claude now returns proper JSON arrays instead of stringified arrays. All nbdev-test tests pass.

@thechandru
Copy link
Author

@jph00 - this is my second attempt at #74

@jph00
Copy link
Collaborator

jph00 commented Mar 12, 2026

Thanks @thechandru for the revised PR. It looks like you accidentally deleted all the outputs. Can you put them back? Try to keep your diff nice and clean! :D

@thechandru
Copy link
Author

thechandru commented Mar 12, 2026

@jph00 - I am not entirely sure how I managed to do that.

I did a run-all and then did a commit from solveit and that seems to have restored outputs. Not sure if I got it back to a sane diff for review. Happy to RTFM - not sure where to look :-)

@jph00
Copy link
Collaborator

jph00 commented Mar 12, 2026

Very good! :)

@jph00 jph00 merged commit 9ce2325 into AnswerDotAI:main Mar 12, 2026
@jph00 jph00 added the bug Something isn't working label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants