Skip to content

fix(types): preserve JSON Schema keywords in responseSchema#169

Open
jckw wants to merge 2 commits intoadaline:mainfrom
jckw:fix/preserve-response-schema-json-keywords
Open

fix(types): preserve JSON Schema keywords in responseSchema#169
jckw wants to merge 2 commits intoadaline:mainfrom
jckw:fix/preserve-response-schema-json-keywords

Conversation

@jckw
Copy link
Copy Markdown

@jckw jckw commented Feb 24, 2026

When chatComplete is called with responseSchema.strict = true, Adaline strips nested JSON Schema keys during parsing, so the forwarded schema is altered and strict structured fails.

Summary

  • preserve unknown JSON Schema keys in response schema validation by using non-destructive parsing
  • add a regression test in OpenAI GPT-5 config transform to ensure nested additionalProperties, $defs, and $ref survive

Root Cause

ResponseSchemaProperty and ResponseSchemaStructure used plain z.object(...), which strips unknown keys by default. This removed valid JSON Schema keywords before request execution.

Fix

  • packages/types/src/config/response-schema.config.ts
    • ResponseSchemaProperty: add .passthrough()
    • ResponseSchemaStructure: add .passthrough()

Validation

  • pnpm exec vitest run core/providers/openai/tests/models/chat-models/base-chat-model.openai.test.ts
  • pre-push hooks also ran full workspace build/test and passed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

Fixed a bug where JSON Schema keywords (additionalProperties, $defs, $ref) were being stripped during response schema validation by adding .passthrough() to ResponseSchemaProperty and ResponseSchemaStructure Zod schemas.

Changes:

  • Added .passthrough() to preserve all JSON Schema keywords in response schema validation
  • Added comprehensive regression test covering nested $defs, $ref, and additionalProperties

Testing:

  • New test verifies nested JSON Schema keywords survive through config transformation
  • Test covers both root-level and nested $defs definitions
  • Test validates $ref references and additionalProperties: false are preserved

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is minimal, well-targeted, and properly tested. Using .passthrough() is the standard Zod approach to preserve unknown keys, which is exactly what's needed for JSON Schema keywords. The regression test thoroughly validates the fix works as intended.
  • No files require special attention

Important Files Changed

Filename Overview
packages/types/src/config/response-schema.config.ts Added .passthrough() to ResponseSchemaProperty and ResponseSchemaStructure to preserve unknown JSON Schema keywords like additionalProperties, $defs, and $ref
core/providers/openai/tests/models/chat-models/base-chat-model.openai.test.ts Added regression test verifying nested JSON Schema keywords (additionalProperties, $defs, $ref) are preserved through config transformation

Last reviewed commit: 7107c26

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +26 to +27
})
.passthrough();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: FunctionParameter and FunctionParameters in function-tool.ts have similar structure but don't use .passthrough() - consider applying the same fix there if they need to preserve JSON Schema keywords

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/types/src/config/response-schema.config.ts
Line: 26-27

Comment:
FYI: `FunctionParameter` and `FunctionParameters` in `function-tool.ts` have similar structure but don't use `.passthrough()` - consider applying the same fix there if they need to preserve JSON Schema keywords

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant