Skip to content

fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples#4629

Merged
yesudeep merged 1 commit intomainfrom
yesudeep/fix/poised-banana
Feb 12, 2026
Merged

fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples#4629
yesudeep merged 1 commit intomainfrom
yesudeep/fix/poised-banana

Conversation

@yesudeep
Copy link
Contributor

@yesudeep yesudeep commented Feb 12, 2026

fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples

  • Fix _convert_schema_property in the Gemini plugin to handle JSON
    Schema nullable types where type is a list (e.g. ['string', 'null'])
    instead of a single string. Extracts the non-null type and sets
    schema.nullable = True on the Gemini Schema object.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the robustness and correctness of the Python Genkit framework. It addresses critical issues related to structlog configuration management, ensures compatibility with DeepSeek's API by correctly handling reasoning content, and enhances the Gemini plugin's ability to interpret nullable JSON Schema types. Additionally, it includes significant cleanup and type refinement in several sample applications, leading to more accurate data handling and better code readability.

Highlights

  • Fix structlog configuration blowaway: Updated structlog.configure calls across multiple telemetry plugins to retrieve and re-apply existing configuration parameters (like wrapper_class, context_class, logger_factory, and cache_logger_on_first_use). This ensures that adding new processors does not inadvertently overwrite or reset other parts of the structlog setup.
  • DeepSeek Reasoning Part Handling: Implemented logic to explicitly strip ReasoningPart instances when converting messages to OpenAI format. This prevents issues with DeepSeek's API, which rejects reasoning_content in multi-turn contexts, aligning behavior with the canonical JavaScript implementation.
  • Nullable JSON Schema Types in Gemini Plugin: Enhanced the Gemini plugin's schema conversion to correctly handle JSON Schema type fields that are defined as lists, allowing for nullable types. It now identifies and sets the nullable flag and extracts the primary non-null type.
  • Sample Code Cleanup and Refinement: Cleaned up various sample files by removing redundant comment blocks, refining data types (e.g., Decimal to float), and adjusting flow return types and processing logic to directly handle structured WeatherResponse objects instead of raw text, addressing potential double JSON encoding issues.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • py/plugins/amazon-bedrock/src/genkit/plugins/amazon_bedrock/telemetry/tracing.py
    • Modified structlog.configure to preserve existing configuration when adding new processors.
  • py/plugins/cloudflare-workers-ai/src/genkit/plugins/cloudflare_workers_ai/telemetry/tracing.py
    • Modified structlog.configure to preserve existing configuration when adding new processors.
  • py/plugins/compat-oai/src/genkit/plugins/compat_oai/models/utils.py
    • Added logic to skip ReasoningPart instances during conversion to OpenAI format.
  • py/plugins/compat-oai/tests/compat_oai_utils_test.py
    • Added test cases to verify ReasoningPart is stripped from assistant messages, including messages with only reasoning content and multi-turn scenarios.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/tracing.py
    • Modified structlog.configure to preserve existing configuration when adding new processors.
  • py/plugins/google-genai/src/genkit/plugins/google_genai/models/gemini.py
    • Updated _convert_schema_property to correctly parse and handle nullable JSON Schema types defined as lists.
  • py/plugins/microsoft-foundry/src/genkit/plugins/microsoft_foundry/telemetry/tracing.py
    • Modified structlog.configure to preserve existing configuration when adding new processors.
  • py/plugins/observability/src/genkit/plugins/observability/init.py
    • Modified structlog.configure to preserve existing configuration when adding new processors.
  • py/samples/framework-realtime-tracing-demo/src/main.py
    • Removed unnecessary comment blocks.
  • py/samples/provider-compat-oai-hello/src/main.py
    • Removed unused Decimal import.
    • Changed latitude, longitude, temperature types from Decimal to float.
    • Updated gablorken type to allow float, str, or None.
    • Modified get_weather_flow and get_weather_flow_stream to return WeatherResponse objects instead of strings.
    • Adjusted flow logic to validate response.output as WeatherResponse.
  • py/samples/provider-vertex-ai-rerank-eval/src/main.py
    • Removed unnecessary comment blocks.
  • py/samples/web-fastapi-bugbot/src/main.py
    • Removed unnecessary comment blocks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@yesudeep yesudeep force-pushed the yesudeep/fix/poised-banana branch from d893474 to 6e43f05 Compare February 12, 2026 21:50
@yesudeep yesudeep changed the title yesudeep/fix/poised banana fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples Feb 12, 2026
@yesudeep yesudeep enabled auto-merge (squash) February 12, 2026 21:50
… up samples

- Fix _convert_schema_property in the Gemini plugin to handle JSON
  Schema nullable types where `type` is a list (e.g. `['string', 'null']`)
  instead of a single string. Extracts the non-null type and sets
  `schema.nullable = True` on the Gemini Schema object.
@yesudeep yesudeep force-pushed the yesudeep/fix/poised-banana branch from 6e43f05 to 9104f85 Compare February 12, 2026 21:52
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several important fixes and cleanups across various plugins and samples. The fix to preserve structlog configuration when adding new processors is crucial, though it introduces some code duplication that could be refactored. The changes to handle ReasoningPart for DeepSeek and nullable types in the Gemini plugin correctly address API compatibility and schema handling issues. Additionally, the cleanup in the samples, such as replacing Decimal with float and improving flow return types, enhances code quality and maintainability. The added tests for the ReasoningPart stripping logic are also a great addition, ensuring the fix is well-covered. Overall, these are solid improvements.

I am having trouble creating individual review comments. Click here to see my feedback.

py/plugins/amazon-bedrock/src/genkit/plugins/amazon_bedrock/telemetry/tracing.py (367-374)

medium

This logic to re-configure structlog while preserving existing settings is a great fix to avoid wiping out other configurations. However, this exact block of code has been duplicated in several other plugin telemetry files:

  • py/plugins/cloudflare-workers-ai/src/genkit/plugins/cloudflare_workers_ai/telemetry/tracing.py
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/tracing.py
  • py/plugins/microsoft-foundry/src/genkit/plugins/microsoft_foundry/telemetry/tracing.py
  • py/plugins/observability/src/genkit/plugins/observability/__init__.py

To improve maintainability and reduce code duplication (D.R.Y. principle), consider extracting this logic into a shared utility function within a core module (e.g., genkit.core.tracing or a new logging utility module).

For example, you could create a helper:

# In a shared utility file
import structlog

def reconfigure_structlog_processors(new_processors: list) -> None:
    """Safely adds new processors to structlog without overwriting other settings."""
    cfg = structlog.get_config()
    structlog.configure(
        processors=new_processors,
        wrapper_class=cfg.get('wrapper_class'),
        context_class=cfg.get('context_class'),
        logger_factory=cfg.get('logger_factory'),
        cache_logger_on_first_use=cfg.get('cache_logger_on_first_use'),
    )

Then, each plugin could simply call reconfigure_structlog_processors(new_processors).

@yesudeep yesudeep merged commit 4daef62 into main Feb 12, 2026
21 checks passed
@yesudeep yesudeep deleted the yesudeep/fix/poised-banana branch February 12, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants