Skip to content

Conversation

adivate2021
Copy link
Contributor

@adivate2021 adivate2021 commented Sep 17, 2025

@adivate2021 adivate2021 marked this pull request as draft September 17, 2025 19:17
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.

Summary of Changes

Hello @adivate2021, 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 a comprehensive system for managing prompts within the application. It establishes a new Prompt dataclass for structured prompt handling, extends the API with dedicated endpoints for prompt insertion and retrieval, and provides corresponding client-side methods and data models. This enhancement streamlines the process of defining, storing, and utilizing dynamic prompt templates.

Highlights

  • New Prompt Dataclass: Introduced a new Prompt dataclass in src/judgeval/prompts/prompt.py to encapsulate prompt definition, storage, and compilation logic. This class includes create and get class methods for interacting with the API, and a compile method for variable substitution.
  • API Endpoint Additions: Added new API endpoints /prompts/insert/ and /prompts/fetch/ to handle the creation and retrieval of prompts. These endpoints are integrated into the API generation scripts.
  • API Client Functionality: Implemented prompts_insert and prompts_fetch methods within both the synchronous and asynchronous API clients (JudgmentSyncClient and JudgmentAsyncClient) to facilitate interaction with the new prompt management endpoints.
  • Data Model Definitions: Defined new TypedDict and Pydantic BaseModel classes (PromptInsertRequest, PromptInsertResponse, PromptFetchResponse) to standardize the data structures for prompt-related API requests and responses.
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 introduces a Prompt dataclass along with methods to create, fetch, and compile prompts, and integrates them into the API. The changes are generally well-structured. However, I've identified a couple of critical issues in src/judgeval/prompts/prompt.py related to unsafe dictionary access for optional fields, which could lead to KeyError exceptions. Additionally, there are a few medium-severity issues concerning code style, a missing type hint, and a potential regression in error handling in prompt_scorer.py that could affect user experience and code consistency. I've provided detailed comments and suggestions for each of these points.

r = client.prompts_insert(
payload={"name": name, "prompt": prompt, "tags": tags}
)
return r["commit_id"], r["parent_commit_id"]
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The parent_commit_id key is not guaranteed to be in the response dictionary r as it is marked as NotRequired in the PromptInsertResponse type definition. Accessing it directly with r["parent_commit_id"] will raise a KeyError if the key is absent. You should use r.get("parent_commit_id") for safe access.

Suggested change
return r["commit_id"], r["parent_commit_id"]
return r["commit_id"], r.get("parent_commit_id")

prompt=prompt_config["prompt"],
tags=prompt_config["tags"],
commit_id=prompt_config["commit_id"],
parent_commit_id=prompt_config["parent_commit_id"],
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The parent_commit_id key is not guaranteed to be in the prompt_config dictionary as it is marked as NotRequired in the PromptFetchResponse type definition. Accessing it directly with prompt_config["parent_commit_id"] will raise a KeyError if the key is absent. You should use prompt_config.get("parent_commit_id") for safe access.

Suggested change
parent_commit_id=prompt_config["parent_commit_id"],
parent_commit_id=prompt_config.get("parent_commit_id"),

Comment on lines +212 to +217
query_params = {}
query_params["name"] = name
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The construction of query_params can be made slightly more concise. While the current implementation is correct, initializing the dictionary with the required name parameter and then conditionally adding optional parameters can improve readability.

Suggested change
query_params = {}
query_params["name"] = name
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag
query_params = {"name": name}
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag

Comment on lines +447 to +452
query_params = {}
query_params["name"] = name
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the synchronous version, the construction of query_params here can be made more concise for better readability.

Suggested change
query_params = {}
query_params["name"] = name
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag
query_params = {"name": name}
if commit_id is not None:
query_params["commit_id"] = commit_id
if tag is not None:
query_params["tag"] = tag

tag: Optional[str] = None,
judgment_api_key: str = os.getenv("JUDGMENT_API_KEY") or "",
organization_id: str = os.getenv("JUDGMENT_ORG_ID") or "",
):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The function fetch_prompt is missing a return type hint. Based on its usage and the prompts_fetch method it calls, the return type should be PromptFetchResponse. Adding type hints improves code clarity and allows for better static analysis. You will also need to import PromptFetchResponse from judgeval.api.api_types.

Suggested change
):
) -> "PromptFetchResponse":

Comment on lines +65 to +66
if not tags:
tags = []
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While if not tags: works, it's more idiomatic and explicit in Python to check for None with if tags is None:. This avoids potential confusion if an empty list is passed intentionally and you wanted to treat it differently from None (though in this case the outcome is the same).

Suggested change
if not tags:
tags = []
if tags is None:
tags = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant