fix: add LLM schema preparation utilities and enhance schema processi… #327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Resolve Google Gemini "schema exceeds maximum nesting depth" error
Problem
Google Gemini API was rejecting structured output requests with a schema validation error:
This occurred because our presentation schemas had deeply nested structures that exceeded Google Gemini's limits:
minLength,maxLength,minItems,maxItemscreate "too many states"Solution
Implemented a schema processing pipeline that:
$refreferences to reduce indirectiontitle)minLength,maxLength,pattern,formatminItems,maxItemsminimum,maximumenum,const,default,examplesChanges
New Files
servers/fastapi/utils/llm_utils.py- Central utility for LLM schema preparation with provider-specific helpers:prepare_schema_for_google()(max_depth=4)prepare_schema_for_openai()(max_depth=5)prepare_schema_for_anthropic()(max_depth=5)Modified Files
servers/fastapi/utils/schema_utils.py- Added schema simplification functionsservers/fastapi/services/llm_client.py- Applied schema processing to all providersservers/fastapi/api/v1/ppt/endpoints/presentation.py- Fixed unawaited coroutine warningsProvider Settings
Result
Schemas are now automatically processed before being sent to LLM providers, preventing validation errors while maintaining the necessary structure for structured output generation.