Skip to content

Fix Gemini structured output + schema cleanup#44

Open
anchpop wants to merge 10 commits intomainfrom
fix-gemini-structured-output
Open

Fix Gemini structured output + schema cleanup#44
anchpop wants to merge 10 commits intomainfrom
fix-gemini-structured-output

Conversation

@anchpop
Copy link
Copy Markdown
Contributor

@anchpop anchpop commented Mar 14, 2026

Summary

  • Fix malformed JSON in structured output schemas: additionalProperties was being duplicated (once from SchemaFormat, once from OpenAiTransform) and added to non-object schemas like string/integer
  • OpenAiTransform now only adds additionalProperties: false to object-type schemas
  • Removed redundant additional_properties field from SchemaFormat
  • Strip additionalProperties from request body when sending to Gemini (they don't support it at all)
  • Added legacy cache key migration so existing cached responses are found under the old key and copied to the new key
  • All legacy migration code is commented with "LEGACY CACHE KEY MIGRATION (can be removed in a future version)"
  • Bumps to v0.17.1

Test plan

  • schema_has_no_duplicate_additional_properties — verifies clean schema, legacy vs new key divergence, and text request key stability
  • openai_structured_output — live OpenAI API test passes
  • gemini_structured_output — live Gemini API test passes
  • cargo check --no-default-features compiles
  • All existing non-flaky tests pass

🤖 Generated with Claude Code

anchpop and others added 10 commits March 13, 2026 00:56
Gemini's OpenAI-compatible endpoint rejects schemas with
additionalProperties. Strip it from the request body when sending to
generativelanguage.googleapis.com, without affecting cache keys.

Also adds Gemini structured output test and bumps to v0.17.1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
tokio macros feature is only available in dev-dependencies,
so the async test needs #[cfg(test)] to avoid compile errors
during cargo check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Requires GEMINI_API_KEY which isn't available in CI.
Run with `cargo test -- --ignored` to include it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CI runs with --no-default-features where dotenvy is unavailable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The schema had duplicate `additionalProperties` keys: one from
SchemaFormat's struct field and another from OpenAiTransform. This
produced malformed JSON that OpenAI started rejecting.

Fix: OpenAiTransform now only adds `additionalProperties` to
object-type schemas (not primitives like string/integer), and the
redundant field is removed from SchemaFormat. Also adds a unit test
to prevent regression, plus an OpenAI integration test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The schema had duplicate additionalProperties keys: one from
SchemaFormat's struct field and another from OpenAiTransform. This
produced malformed JSON.

Fix:
- OpenAiTransform now only adds additionalProperties to object-type
  schemas (not primitives like string/integer)
- Removed redundant additionalProperties field from SchemaFormat
- Added legacy cache key migration so existing caches are found under
  the old key format and copied to the new key

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The schema fix (only adding additionalProperties to object-type
schemas, no duplicates) makes the Gemini-specific stripping in
chat_uncached redundant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add InputAudio variant to ChatMessageContent for sending audio
  (wav/mp3) as base64-encoded data in chat completions
- Add InputAudio struct with wav() and mp3() convenience constructors
- Add base64 dependency
- Move harvard.wav to test_fixtures/
- Add gemini_audio_transcription integration test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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