Skip to content

Comments

feat(go/plugins/anthropic): support native structured output#4701

Open
hugoaguirre wants to merge 8 commits intomainfrom
haguirre/anthropic_json
Open

feat(go/plugins/anthropic): support native structured output#4701
hugoaguirre wants to merge 8 commits intomainfrom
haguirre/anthropic_json

Conversation

@hugoaguirre
Copy link
Contributor

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hugoaguirre, 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 introduces native support for structured JSON output when interacting with Anthropic models. By leveraging Anthropic's tool use capabilities, it allows developers to specify a JSON schema for the desired output, ensuring that model responses adhere to a predefined structure. This enhancement streamlines the integration of Anthropic models into applications that require reliable and parseable data formats, improving developer experience and reducing post-processing efforts.

Highlights

  • Enhanced Model Capabilities: Updated default Claude model options to support Multimodal capabilities, laying groundwork for more advanced interactions.
  • Native Structured Output Support: Implemented core logic to detect and process requests for structured JSON output, both for non-streaming and streaming responses from Anthropic models.
  • Tool-Based JSON Transformation: Introduced a new handleStructuredOutput helper function that transforms Anthropic's internal tool call responses into raw JSON output, ensuring adherence to specified schemas.
  • Dynamic Request Generation: Modified the toAnthropicRequest function to dynamically add a return_json_output tool and enforce its use via ToolChoice when a JSON output schema is provided in the model request.
  • Comprehensive Testing: Added a dedicated test case (TestToAnthropicRequest_StructuredOutput) to verify the correct generation of Anthropic requests for structured output, ensuring reliability of the new feature.

🧠 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
  • go/plugins/anthropic/models.go
    • Updated default Claude model options to support Multimodal capabilities.
  • go/plugins/internal/anthropic/anthropic.go
    • Added isStructured flag to identify structured output requests.
    • Integrated handleStructuredOutput calls for both streaming and non-streaming responses.
    • Extended streaming event handling to process input_json_delta for structured output.
    • Implemented handleStructuredOutput function to convert tool requests to JSON text.
    • Modified toAnthropicRequest to include a return_json_output tool and set ToolChoice when a JSON output schema is present.
  • go/plugins/internal/anthropic/anthropic_test.go
    • Added encoding/json import.
    • Introduced TestToAnthropicRequest_StructuredOutput to validate structured output request generation.
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.

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 adds support for native structured output in the Anthropic Go plugin. The changes look good overall. I've identified a few areas for improvement:

  • Error Handling: There's a place where an error from json.Marshal is ignored, which could lead to silent failures.
  • Maintainability: There's some duplicated code for checking structured output conditions and a hardcoded string that could be extracted into a constant.
  • Testing: The new test for structured output could be more robust in its schema verification.

I've left specific comments with suggestions for these points.

@hugoaguirre
Copy link
Contributor Author

/gemini review

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 adds support for native structured output to the Anthropic Go plugin by leveraging the OutputConfig feature in the updated Anthropic SDK. The changes include updating the model capabilities, modifying the request creation to use OutputConfig for constrained JSON output, and making tool schemas stricter. New live tests have been added to verify the structured output functionality in both regular and streaming modes.

My review focuses on improving code maintainability by reducing duplication in tests, enhancing the robustness of the schema enforcement logic, and correcting a unit test that was verifying an outdated implementation pattern. Overall, this is a great feature addition.

@hugoaguirre
Copy link
Contributor Author

/gemini review

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 adds support for native structured output in the Anthropic Go plugin. The changes include updating the Anthropic SDK, modifying the model capabilities to declare support for constrained generation, and implementing the logic to use Anthropic's OutputConfig for structured output requests. New live tests have been added to verify this functionality for both streaming and non-streaming cases. The implementation looks solid, but I've identified a couple of areas where in-place modification of schemas could lead to side effects, and a minor redundancy in a test case.

@hugoaguirre hugoaguirre marked this pull request as ready for review February 18, 2026 21:13
@hugoaguirre hugoaguirre enabled auto-merge (squash) February 18, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

1 participant