Skip to content

[Fix] Returning Correct Prompt Response Type - #303

Merged
antonio-amjr merged 1 commit into
project-chip:v2.14.1-developfrom
antonio-amjr:fix/prompt_response_return_wrong_type
Mar 10, 2026
Merged

[Fix] Returning Correct Prompt Response Type#303
antonio-amjr merged 1 commit into
project-chip:v2.14.1-developfrom
antonio-amjr:fix/prompt_response_return_wrong_type

Conversation

@antonio-amjr

Copy link
Copy Markdown
Contributor

Fix: project-chip/certification-tool#907

Description

There's a problem when executing the CLI that pydantic type coercion is interpreting the response type as integer, since the response type is an Python's Union of int or str (line 24 of file prompt_response.py).

Solution

As the response_str variable should always return string, forcing the return to cast to str seems straight forward and error prune.

Version

This is affecting the TH v2.14.1-beta2+winter2026 (Matter 1.5.1 MVE)

Testing

The Test case and scenario pointed by the issue#907 is now passing for the TH version used:

Screenshot 2026-03-10 at 09 56 46

@antonio-amjr antonio-amjr self-assigned this Mar 10, 2026
@antonio-amjr antonio-amjr added the bug Something isn't working label Mar 10, 2026
@antonio-amjr
antonio-amjr merged commit 78edc1b into project-chip:v2.14.1-develop Mar 10, 2026
7 of 8 checks passed
@antonio-amjr
antonio-amjr deleted the fix/prompt_response_return_wrong_type branch March 10, 2026 13:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 resolves a critical type coercion bug affecting CLI execution in the certification tool. By explicitly casting prompt responses to strings, it ensures that pydantic correctly handles user input, preventing errors and improving the robustness of the CLI.

Highlights

  • Type Coercion Fix: Addressed an issue where pydantic was incorrectly interpreting prompt responses as integers due to a Union[int, str] type, leading to CLI execution problems.
  • Explicit String Casting: Implemented explicit casting of the 'response' value to a string when assigning it to 'self.response_str', ensuring correct type handling and preventing runtime errors.

🧠 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
  • app/user_prompt_support/prompt_response.py
    • Ensured 'response_str' is always a string by adding explicit 'str()' casting and handling 'None' values.
Activity
  • The pull request was created to address issue #907.
  • The author provided a detailed description, solution, affected version, and testing evidence including a screenshot.
  • No further human activity (comments, reviews) has occurred since the PR creation.
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.

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

Copy link
Copy Markdown
Contributor

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 addresses a type coercion issue with Pydantic where a response was being incorrectly interpreted as an integer. The fix ensures the response_str attribute is always a string or None, which is correct. I have one suggestion to make the implementation more concise.

Comment on lines +38 to +40
self.response_str = (
str(kwargs["response"]) if kwargs["response"] is not None else None
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While the current implementation is correct, it can be made more concise and avoid repetition by using an assignment expression (walrus operator, :=). This assigns the value of kwargs['response'] to a variable and checks if it's not None in the same expression, improving readability and maintainability.

            self.response_str = str(v) if (v := kwargs["response"]) is not None else None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants