Skip to content

fix(agent): skeletonFromJsonSchema handles nullable type-union shape - #634

Open
ygd58 wants to merge 1 commit into
sapiom:mainfrom
ygd58:fix/nullable-type-union-skeleton
Open

fix(agent): skeletonFromJsonSchema handles nullable type-union shape#634
ygd58 wants to merge 1 commit into
sapiom:mainfrom
ygd58:fix/nullable-type-union-skeleton

Conversation

@ygd58

@ygd58 ygd58 commented Aug 14, 2026

Copy link
Copy Markdown

Fixes #614

exampleFromJsonSchema (via its internal skeletonFromJsonSchema helper) returned null for any field whose JSON Schema type is an array containing "null" (e.g. { type: ["string", "null"] }), instead of a type-appropriate placeholder. The switch(schema.type) statement never matched an array, so it always fell through to the null default.

The type field can validly be an array of alternatives per the JSON Schema spec, and some Zod versions (and non-Zod JSON Schema producers) represent a nullable field this way rather than as anyOf. exampleFromJsonSchema is a public entry point for schemas generated by whatever tooling the caller uses (per its own doc comment), so this shape must be handled regardless of which zod version/tool produced it - not just the anyOf branch already handled above.

Fix: normalize an array type to its non-null member before the switch.

Tests: this repo's bundled zod version actually produces anyOf for .nullable() (not a type array), so the zod-based tests pass via the pre-existing anyOf handling and mainly guard against regressions there. The raw type-array tests (constructing { type: [...] } directly) exercise the actual fix and fail without it - verified by temporarily reverting the fix and confirming that test failed, then restoring it.

Changeset: added (@sapiom/agent, patch).

Verified locally: vitest run src/introspection.test.ts (5/5 passing), eslint clean.

Fixes sapiom#614

exampleFromJsonSchema (via its internal skeletonFromJsonSchema helper)
returned null for any field whose JSON Schema type is an array
containing "null" (e.g. { type: ["string", "null"] }), instead of a
type-appropriate placeholder. The switch(schema.type) statement never
matched an array, so it always fell through to the null default.

The type field can validly be an array of alternatives per the JSON
Schema spec, and some Zod versions (and non-Zod JSON Schema producers)
represent a nullable field this way rather than as anyOf.
exampleFromJsonSchema is a public entry point for schemas generated by
whatever tooling the caller uses (per its own doc comment), so this
shape must be handled regardless of which zod version/tool produced
it - not just the anyOf branch already handled above.

Fix: normalize an array type to its non-null member before the switch.

Tests: this repo's bundled zod version actually produces anyOf for
.nullable() (not a type array), so the zod-based tests pass via the
pre-existing anyOf handling and mainly guard against regressions there.
The raw type-array tests (constructing { type: [...] } directly)
exercise the actual fix and fail without it - verified by temporarily
reverting the fix and confirming that test failed, then restoring it.

Changeset added (patch, @sapiom/agent).
@github-actions github-actions Bot added contribution: incomplete Required pull request information is incomplete or ambiguous contributor: external Pull request author does not have write, maintain, or admin access to sapiom-js needs-triage Awaiting maintainer review and classification review: manual External pull request requires maintainer review before automation size: small Review size is at most 100 changed lines area: agents Changes to agent authoring, core, or runtime labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Changes to agent authoring, core, or runtime contribution: incomplete Required pull request information is incomplete or ambiguous contributor: external Pull request author does not have write, maintain, or admin access to sapiom-js needs-triage Awaiting maintainer review and classification review: manual External pull request requires maintainer review before automation size: small Review size is at most 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agent: skeletonFromJsonSchema ignores array form type (nullable types always return null)

1 participant