Look at https://github.com/moltis-org/moltis/issues/743 and suggest a fix
Private research annotation
Sign in to add a private research label or note.
- User
Look at https://github.com/moltis-org/moltis/issues/743 and suggest a fix
Assistant
Now I have the full picture. Let me verify what
json_schema_astdoes with the$schemafield.Assistant
- User
Add a test to reproduce the issue, then fix it, then run the test to ensure it worked.
Assistant
Let me start by reading the test file to understand the existing test patterns.
Assistant
Now I have the full picture. Let me add the failing test first, then apply the fix.
Assistant
Now let me run the tests to confirm they fail (reproducing the bug):
Assistant
Good — it's a
#[cfg(test)]module. The test should be found asopenai_compat::tests::sanitize_draft07_schema_strips_unsupported_keywords. Let me run it with the right filter:Assistant
Tests are listed. I need
--libflag to find them:Assistant
The test passes on keyword stripping, but that's not the full bug. The real issue is what's left after stripping — empty schemas in
anyOfthat OpenAI rejects. Let me make the test more precise:Assistant
Test fails as expected — stripping
notleaves{}insideanyOf. The output confirms the bug:json{"properties":{"query":{"anyOf":[{"anyOf":[{},{"type":"string"}]},{"type":"null"}]}},"type":"object"}Now let me also confirm the second test fails:
Assistant
That one passes because it only checks keyword removal. Let me strengthen it:
Assistant
Both tests fail, confirming the bug. Now let me apply the fix — strip
$schemabefore passing toSchemaDocument::from_json():Assistant
Also update the fallback returns to use
input(with$schemaalready stripped) instead ofschema:Assistant
The fallback paths still return
schema.clone()(the original with$schema). They should returninputinstead since$schemawill be stripped anyway:Assistant
Now run the tests:
Assistant
Canonicalization runs now (the schema changed), but
notcanonicalizes to the empty/true schema{}, which survives keyword filtering. I need a transform to clean up empty schemas withinanyOf/oneOf/allOf:Assistant
Now I need to add a transform that strips empty
{}schemas fromanyOf/oneOf/allOfand unwraps single-variant composites. The empty{}is the JSON Schema "true" schema (accepts anything), which is a no-op inanyOfand subsumes everything — but OpenAI rejects it.Assistant
Now wire it into the transform pipeline, after the keyword subset transform:
Assistant
Both tests pass. Now let's make sure all existing tests in this module still pass:
Assistant
All 21 tests pass — no regressions. Let me verify the final state of the changed files:
Assistant
Clean. Let me also run the broader test suite for the crate to check for regressions:
Assistant
All 128 tests pass, zero failures.
Summary
Two-part fix in
schema_normalization.rs:-
Strip
$schemabefore canonicalization (lines 182-185): Removes the$schemakey from the input before passing toSchemaDocument::from_json(), so draft-07, draft-04, and any other non-2020-12 schemas get the same AST canonicalization treatment. The$schemakey would be stripped later byOpenAiSchemaSubsetTransformanyway. -
New
SimplifyCompositeTransform(lines 89-127): After keyword stripping, canonicalization ofnotleaves empty{}(the "true" schema) insideanyOf/oneOf. This transform removes those empty variants and collapses single-variant composites inline. Runs afterOpenAiSchemaSubsetTransformand beforeRestoreEnumTypeTransform.
Tests added in
tests.rs:sanitize_draft07_schema_strips_unsupported_keywords— reproduces the exact Attio schema pattern from #743, asserts no$schema, , or empty survive
-
- User
commit push and create a PR
Assistant
PR created: https://github.com/moltis-org/moltis/pull/746
- User
Fix and solve PR comments
Assistant
Two Greptile comments — both reasonable. Let me apply them.
Assistant
All 21 pass. Now commit and push.
Assistant
Push needs a YubiKey tap. Please tap your YubiKey and I'll retry.
Assistant
Still failing — please tap your YubiKey and let me know when ready to retry.