Skip to content

fix(cron): flatten schedule schema for Gemini tool compatibility#221

Open
bohuslav-broza wants to merge 1 commit intovirattt:mainfrom
bohuslav-broza:fix/gemini-cron-schema
Open

fix(cron): flatten schedule schema for Gemini tool compatibility#221
bohuslav-broza wants to merge 1 commit intovirattt:mainfrom
bohuslav-broza:fix/gemini-cron-schema

Conversation

@bohuslav-broza
Copy link
Copy Markdown

@bohuslav-broza bohuslav-broza commented Apr 3, 2026

Summary

Gemini API (v1beta) currently does not support oneOf or const keywords in tool function declarations. Using z.discriminatedUnion in the cron tool's schema generates a JSON schema with these keywords, causing a 400 Bad Request (Invalid JSON payload) during initialization when using Gemini models.

Changes

  • Refactored scheduleSchema in src/tools/cron/cron-tool.ts from a discriminated union to a flat object with optional fields.
  • Updated descriptions for the now-optional fields (at, everyMs, expr) to indicate their requirement based on the selected kind.

Impact

  • Fixes launch-blocking 400 errors for users with Gemini models.
  • Maintains full functionality for existing scheduling logic (the cast to CronSchedule remains safe as the flat object is a superset of the possible union members).

Error Reference

⏺ Error: [Google API] [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-flash-latest:generateContent: [400 Bad Request] Invalid JSON payload received. Unknown name "const" at 'tools[0].function_declarations[10].parameters.properties[3].value.one_of...'

Gemini API (v1beta) does not support 'oneOf' or 'const' in function declarations. Replacing the discriminatedUnion with a flat object with optional fields ensures the generated JSON schema is compatible with Google's API while maintaining existing logic.
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