Skip to content

Conversation

@ssbushi
Copy link
Contributor

@ssbushi ssbushi commented Dec 19, 2025

image

Code:

import { googleAI } from "@genkit-ai/google-genai";
import { genkit, disableSchemaCodeGeneration } from "genkit";

const ai = genkit({
  plugins: [googleAI({ apiKey: "..." })],
  model: googleAI.model("gemini-2.5-flash", {
    temperature: 0.8,
  }),
});

disableSchemaCodeGeneration();

export interface Env {}

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    const { text } = await ai.generate({
      prompt: `Tell me a joke about banana`,
    });
    return new Response(JSON.stringify({ message: text }), {
      headers: {
        "content-type": "application/json;charset=UTF-8",
      },
    });
  },
};

Fixes: #3968

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ssbushi, 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 enhances Genkit's schema validation system by introducing a configurable mechanism to disable runtime schema compilation. This is particularly beneficial for environments with strict security policies, such as CloudFlare Workers, where dynamic code generation is restricted. By integrating an interpretive JSON schema validator, the system can now operate effectively in these constrained environments while maintaining robust schema validation capabilities.

Highlights

  • Runtime Schema Compilation Control: Introduced a new function disableSchemaCodeGeneration() to allow users to opt-out of runtime schema compilation, providing more flexibility for deployment environments.
  • CloudFlare Worker Compatibility: This change specifically addresses environments like CloudFlare Workers that restrict dynamic code execution (e.g., eval, new Function) by providing an alternative interpretive schema validation method.
  • New Dependency for Interpretive Validation: Integrated the @cfworker/json-schema library to provide the necessary interpretive validation capabilities without relying on runtime compilation.
  • Updated Schema Validation Logic: Modified the core validateSchema function to conditionally use either the traditional ajv.compile (default) or the new interpretive validator based on the configured validationMode.
  • Enhanced Test Coverage: Added a dedicated test case to ensure the disableSchemaCodeGeneration() function correctly switches the validation mode and verifies that ajv.compile is not invoked when interpretive mode is active.

🧠 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.

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.

@ssbushi ssbushi requested a review from pavelgj December 19, 2025 16:28
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 a new feature to disable schema code generation at runtime, primarily for environments like CloudFlare workers that restrict eval or new Function. This is implemented by adding a disableSchemaCodeGeneration() function that switches the validation mode from 'compile' (using ajv.compile) to 'interpret' (using the newly added @cfworker/json-schema library). The validateSchema function was updated with conditional logic to support this new mode, including new error detail conversion functions for Zod and @cfworker/json-schema. The package.json and pnpm-lock.yaml files were updated to include the new dependency. Initial test cases were added to verify the disableSchemaCodeGeneration functionality for JSON schemas. However, the review comments point out a flaw where Zod's native safeParse is prioritized over the 'interpret' mode, even when code generation is disabled, defeating the purpose for Zod schemas. A suggestion is made to adjust the validation logic to ensure Zod's native validation only occurs in 'compile' mode, and a new test case for Zod schemas in 'interpret' mode is requested to prevent future regressions.

@ssbushi ssbushi merged commit dbf142f into main Dec 19, 2025
5 checks passed
@ssbushi ssbushi deleted the sb/cfworker branch December 19, 2025 20:36
pavelgj added a commit that referenced this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants