feat(py): Return pydantic instances when output schema passed in as P…#4413
feat(py): Return pydantic instances when output schema passed in as P…#4413
Conversation
Summary of ChangesHello @huangjeff5, 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 significantly enhances the Python Genkit SDK by integrating robust type-checking and Pydantic validation for prompt inputs and outputs. These changes allow developers to define schemas for prompt data, enabling static type inference at design time and ensuring data integrity through runtime validation. The update aims to improve code reliability, maintainability, and overall developer experience by providing clearer data contracts and automated validation for AI prompt interactions. Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces excellent support for typed inputs and outputs using Pydantic models in the Python SDK. The use of overloads for ai.prompt provides great type inference for developers. The propagation of schema_type for runtime validation is well-implemented, culminating in the GenerateResponseWrapper.output property which now returns validated Pydantic instances. The changes are comprehensive and significantly improve the developer experience. I have one suggestion regarding code duplication to enhance maintainability.
There was a problem hiding this comment.
Code Review
This pull request introduces typed input and output schemas for prompts, enabling static type checking and runtime Pydantic validation. The changes are well-structured, adding overloads for ai.prompt and propagating schema types through the generation pipeline. I've identified a potential logic issue in to_generate_action_options related to output_constrained handling and also noted some code duplication that could be refactored for better maintainability. Overall, this is a great enhancement to the SDK's type safety.
…enkit into jh-pydantic-dotprompt
This PR adds typed input and output support to the Python Genkit SDK, enabling static type inference and runtime Pydantic validation for prompts.
API changes