fix: resolve no matching overload errors in LLMGenerator#33243
fix: resolve no matching overload errors in LLMGenerator#33243warren830 wants to merge 1 commit intolanggenius:mainfrom
Conversation
…m_generator Add explicit list[PromptMessage] type annotations to prompt message lists in LLMGenerator to resolve type checker overload matching errors. The issue was that lists containing UserPromptMessage or SystemPromptMessage subclasses were inferred as list[UserPromptMessage] etc., which didn't match the invoke_llm overload signature expecting list[PromptMessage]. Changes: - Added explicit list[PromptMessage] type annotations to all prompt_messages variable declarations in llm_generator.py - Removed unnecessary list() wrapping since the variables are already lists with the correct type annotation
Summary of ChangesHello, 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 addresses a type checking issue in the 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
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 improves type safety by explicitly annotating prompt message lists as list[PromptMessage] and removing unnecessary list() calls in llm_generator.py. While these changes are beneficial for code maintainability, a high-severity Insecure Direct Object Reference (IDOR) vulnerability was identified in the instruction_modify methods. These methods fetch application and message data based on user-supplied IDs without verifying tenant ownership, which could lead to unauthorized data access. It is recommended to implement proper authorization checks in the data fetching logic.
| try: | ||
| response: LLMResult = model_instance.invoke_llm( | ||
| prompt_messages=list(prompt_messages), model_parameters=model_parameters, stream=False | ||
| prompt_messages=prompt_messages, model_parameters=model_parameters, stream=False |
There was a problem hiding this comment.
The invoke_llm call on this line processes last_run data that is fetched in the calling methods (instruction_modify_workflow and instruction_modify_legacy) without proper authorization checks. Specifically, instruction_modify_workflow (line 434) and instruction_modify_legacy (line 392) fetch App and Message objects using only a user-supplied flow_id (App ID) without verifying that these objects belong to the provided tenant_id. This allows an authenticated user to potentially leak sensitive information (inputs, outputs, logs) from any workflow run by providing its ID.
To remediate this, update the calling methods to verify ownership before processing the data. For example, in instruction_modify_workflow, change the query to: session.query(App).where(App.id == flow_id, App.tenant_id == tenant_id).first().
Description
Fixes #32494
The type checker reports
no-matching-overloaderrors forinvoke_llmcalls inllm_generator.pybecause prompt message lists were inferred aslist[UserPromptMessage]instead oflist[PromptMessage].Root Cause
When creating a list like
[UserPromptMessage(content=prompt)], Python's type system infers it aslist[UserPromptMessage]. Theinvoke_llmoverload withstream: Literal[False]expectslist[PromptMessage]. Sincelistis invariant in Python's type system,list[UserPromptMessage]doesn't matchlist[PromptMessage]even thoughUserPromptMessageis a subclass ofPromptMessage.Changes
list[PromptMessage]type annotations to all prompt message list declarations inLLMGeneratorlist()wrapping calls since the variables are already properly typed listsgenerate_conversation_name,generate_suggested_questions_after_answer,generate_rule_config,generate_code,generate_structured_output, and__instruction_modify_commonType of Change