Skip to content

feat(py): add array, enum, and jsonl output formats for JS parity#4230

Merged
yesudeep merged 1 commit intomainfrom
yesudeep/feat/premium-question
Jan 22, 2026
Merged

feat(py): add array, enum, and jsonl output formats for JS parity#4230
yesudeep merged 1 commit intomainfrom
yesudeep/feat/premium-question

Conversation

@yesudeep
Copy link
Contributor

Add missing output formats to achieve feature parity with the canonical
JavaScript implementation:

  • array: Parses model output as a JSON array of objects. Uses
    extract_items for robust parsing of streaming chunks.
  • enum: Constrains model to output a single value from a predefined
    list. Useful for classification tasks.
  • jsonl: Parses newline-delimited JSON objects. Optimized for
    streaming scenarios where each object can be processed independently.

CHANGELOG:

  • Add ArrayFormat, EnumFormat, and JsonlFormat implementations
  • Update FormatterConfig to match JS canonical behavior:
    • enum: content_type='text/enum', constrained=True
    • array: content_type='application/json', constrained=True
    • jsonl: content_type='application/jsonl' (unconstrained)
    • text: content_type='text/plain' (unconstrained)
  • Fix TextFormat.chunk_parser to return chunk.text (current chunk only)
    instead of accumulated_text, matching JS behavior
  • Fix GenerateResponseChunkWrapper.accumulated_text to correctly
    accumulate text from previous chunks
  • Update _aio.py to safely handle OutputConfig using getattr() since
    typing.py is auto-generated and may not have all fields
  • Add comprehensive documentation with format comparison table
  • Add unit tests for all new formats
  • Add format-demo sample demonstrating all five formats with
    pre-populated inputs:
    • generate_haiku_text (text format)
    • get_country_info_json (json format)
    • recommend_books_array (array format)
    • classify_sentiment_enum (enum format)
    • create_story_characters_jsonl (jsonl format)

@yesudeep yesudeep requested a review from MengqinShen January 22, 2026 15:47
@github-actions github-actions bot added docs Improvements or additions to documentation feature New feature or request python Python config labels Jan 22, 2026
@yesudeep yesudeep enabled auto-merge (squash) January 22, 2026 15:47
@yesudeep yesudeep force-pushed the yesudeep/feat/premium-question branch from f86a4d8 to af67bfc Compare January 22, 2026 15:48
@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 significantly enhances the Python Genkit library by introducing three new output formats: array, enum, and jsonl, bringing it to feature parity with its JavaScript counterpart. The changes centralize output configuration through a new OutputConfig parameter in the generate and generate_stream APIs, making it easier to specify desired output structures. It also includes critical fixes for streaming text accumulation and parsing, ensuring robust handling of model responses. A new comprehensive sample demonstrates the practical application of all available output formats.

Highlights

  • New Output Formats: Introduced array, enum, and jsonl output formats for Python, achieving feature parity with the JavaScript implementation.
  • Centralized Output Configuration: Added a new output parameter of type OutputConfig (or dictionary) to ai.generate and ai.generate_stream functions, consolidating output-related settings.
  • Robust Streaming Parsing: Implemented advanced parsing logic for streaming chunks in array and jsonl formats, using extract_items and line-by-line processing, respectively, to handle incomplete or noisy output.
  • Formatter Configuration Updates: Updated FormatterConfig for all formats to align with canonical behavior, including content_type and constrained properties.
  • Core Logic Fixes: Corrected TextFormat.chunk_parser to return only the current chunk's text and fixed GenerateResponseChunkWrapper.accumulated_text for accurate text accumulation across chunks.
  • Comprehensive Sample & Tests: Added a new format-demo sample showcasing all five output formats and included dedicated unit tests for the new array, enum, and jsonl formats.

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

@yesudeep yesudeep disabled auto-merge January 22, 2026 15:50
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 new output formats (array, enum, jsonl) to achieve feature parity with the JavaScript implementation, along with comprehensive documentation and unit tests. The changes also include improvements to how output configurations are handled and fixes for text accumulation in streaming responses. Overall, the changes are well-structured and enhance the functionality of the Genkit Python library.

Add missing output formats to achieve feature parity with the canonical
JavaScript implementation:

- **array**: Parses model output as a JSON array of objects. Uses
  `extract_items` for robust parsing of streaming chunks.
- **enum**: Constrains model to output a single value from a predefined
  list. Useful for classification tasks.
- **jsonl**: Parses newline-delimited JSON objects. Optimized for
  streaming scenarios where each object can be processed independently.

CHANGELOG:
- Add ArrayFormat, EnumFormat, and JsonlFormat implementations
- Update FormatterConfig to match JS canonical behavior:
  - enum: content_type='text/enum', constrained=True
  - array: content_type='application/json', constrained=True
  - jsonl: content_type='application/jsonl' (unconstrained)
  - text: content_type='text/plain' (unconstrained)
- Fix TextFormat.chunk_parser to return chunk.text (current chunk only)
  instead of accumulated_text, matching JS behavior
- Fix GenerateResponseChunkWrapper.accumulated_text to correctly
  accumulate text from previous chunks
- Update _aio.py to safely handle OutputConfig using getattr() since
  typing.py is auto-generated and may not have all fields
- Add comprehensive documentation with format comparison table
- Add unit tests for all new formats
- Add format-demo sample demonstrating all five formats with
  pre-populated inputs:
  - generate_haiku_text (text format)
  - get_country_info_json (json format)
  - recommend_books_array (array format)
  - classify_sentiment_enum (enum format)
  - create_story_characters_jsonl (jsonl format)
@yesudeep yesudeep force-pushed the yesudeep/feat/premium-question branch from af67bfc to d527e38 Compare January 22, 2026 16:04
@yesudeep yesudeep enabled auto-merge (squash) January 22, 2026 16:05
@yesudeep yesudeep requested a review from zarinn3pal January 22, 2026 16:17
@yesudeep yesudeep merged commit 6bf612b into main Jan 22, 2026
22 checks passed
@yesudeep yesudeep deleted the yesudeep/feat/premium-question branch January 22, 2026 16:18
This was referenced Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation feature New feature or request python Python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants