Prompt
Create and iterate on prompts that you can dynamically load into your production environments.
The Prompt class provides an interface to easily create and version prompts that are stored on the Judgment platform. You can then dynamically retrieve any version of any prompt to be used in your application code.
Prompt's versioning system allows you to iterate on commits by creating multiple commits. You can also label prompt commits with tags that serve as a keywords to retrieve a specific version of a prompt.
from openai import OpenAI
from judgeval.prompt import Prompt
# Create a prompt. If the prompt name already exists, a new commit will be created
Prompt.create(
project_name="default_project",
name="Movie Recommendation Prompt",
prompt="""Given this genre: {{genre}} and this decade: {{decade}},
can you recommend a movie of that genre that was released in that decade?""",
tags=["production"],
)
class MovieRecommendationAgent:
def __init__(self):
self.client = OpenAI()
def get_recommendation(self, user_genre: str, user_decade: str):
prompt = Prompt.get(
project_name="default_project",
name="Movie Recommendation Prompt",
tag="production"
)
response = self.client.chat.completions.create(
model="gpt-5",
messages=[
{
"role": "user",
"content": prompt.compile(genre=user_genre, decade=user_decade)
}
]
)
return f"Response: {response.choices[0].message.content}"
if __name__ == "__main__":
agent = MovieRecommendationAgent()
agent.get_recommendation("horror", "90s")Prompt.create()
Initialize a Prompt object.
Prompt.create(
project_name: str,
name: str,
prompt: str,
tags: Optional[List[str]] = None,
judgment_api_key: Optional[str] = None,
organization_id: Optional[str] = None
)Parameters
The name of the prompt, which is unique to each prompt. Specifying a name that already exists will create a new commit for that prompt
The prompt contents to save. Use {{ mustache notation }} for variables
to specify parts of the prompt that can be dynamically replaced at runtime
using Prompt.compile()
If specified, the tags in this list will be attached to the created commit. Please read the warning in the Overview section for more details on tagging behavior
Recommended - set using the JUDGMENT_API_KEY environment variable
Recommended - set using the JUDGMENT_ORG_ID environment variable
Example
from judgeval.prompt import Prompt
prompt = Prompt.create(
project_name="default_project",
name="Test Prompt",
prompt="Recommend a movie in the {{genre}} genre",
tags=["production"],
)Prompt.get()
Retrieve the latest version of a Prompt that has already been created for the project.
- Passing in a
commit_idwill retrieve the commit with that id for the prompt, if it exists. - Passing in a
tagwill retrieve the commit for the prompt with thattagattached, if it exists.
Prompt.get(
project_name: str,
name: str,
commit_id: Optional[str] = None,
tag: Optional[str] = None,
judgment_api_key: Optional[str] = None,
organization_id: Optional[str] = None
)Parameters
The name of the project to fetch the prompt from
The name of the Prompt you would like to retrieve. Throws a JudgmentException if the prompt does not exist
The ID of the prompt commit you would like to retrieve. Mutually exclusive with tag. Throws a JudgmentException if the prompt commit does not exist
The tag associated with the prompt commit you would like to retrieve. Mutually exclusive with commit_id. Throws a JudgmentException if the prompt commit does not exist
Recommended - set using the JUDGMENT_API_KEY environment variable
Recommended - set using the JUDGMENT_ORG_ID environment variable
Returns
A Prompt instance.
The Prompt instance will have the following metadata fields:
creator_first_name: The first name of the user who created the promptcreator_last_name: The last name of the user who created the promptcreator_email: The email of the user who created the prompt
Example
from judgeval.prompt import Prompt
prompt = Prompt.get(project_name="default_project", name="Test Prompt")Prompt.tag()
Attach one or more tags to a specific version of a Prompt that has already been created for the project.
Prompt.tag(
project_name: str,
name: str,
commit_id: Optional[str] = None,
tags: Optional[List[str]] = None,
judgment_api_key: Optional[str] = None,
organization_id: Optional[str] = None
)Parameters
The name of the project that the prompt you would like to tag is in
The name of the Prompt you would like to tag. Throws a JudgmentException
if the prompt does not exist
The ID of the prompt commit you would like to attach tag(s) to. Throws a
JudgmentException if the prompt commit does not exist
The tag(s) you would like to add to the prompt commit. Throws a
JudgmentException if this list is empty
Recommended - set using the JUDGMENT_API_KEY environment variable
Recommended - set using the JUDGMENT_ORG_ID environment variable
Returns
A str representing the commit ID which the tag(s) were attached to.
Example
from judgeval.prompt import Prompt
commit_id = Prompt.tag(
project_name="default_project",
name="Test Prompt",
commit_id="some_commit_id",
tags=["production", "v1.2"],
)Prompt.untag()
Remove one or more tags attached to any of the versions of a Prompt that has already been created for the project.
Prompt.untag(
project_name: str,
name: str,
tags: Optional[List[str]] = None,
judgment_api_key: Optional[str] = None,
organization_id: Optional[str] = None
)Parameters
The name of the project that the prompt you would like to untag is in
The name of the Prompt you would like to untag. Throws a JudgmentException if the prompt does not exist
The tag(s) you would like to remove from the prompt. Throws a JudgmentException if this list is empty or if the prompt does not have any of the provided tags
Recommended - set using the JUDGMENT_API_KEY environment variable
Recommended - set using the JUDGMENT_ORG_ID environment variable
Returns
A List[str] representing the commit IDs which the tag(s) were removed from.
Example
from judgeval.prompt import Prompt
prompt = Prompt.untag(
project_name="default_project",
name="Test Prompt",
tags=["production"],
)Prompt.list()
Retrieve all the versions of a Prompt that has already been created for the project.
Prompt.list(
project_name: str,
name: str,
judgment_api_key: Optional[str] = None,
organization_id: Optional[str] = None
)Parameters
The name of the project to fetch the prompt from
The name of the Prompt whose versions you would like to retrieve. If the prompt does not exist, an empty list will be returned
Recommended - set using the JUDGMENT_API_KEY environment variable
Recommended - set using the JUDGMENT_ORG_ID environment variable
Returns
A List[Prompt] representing the versions of the prompt. Each Prompt in the list will have the following metadata fields:
creator_first_name: The first name of the user who created the promptcreator_last_name: The last name of the user who created the promptcreator_email: The email of the user who created the prompt
Example
from judgeval.prompt import Prompt
prompts = Prompt.list(project_name="default_project", name="Test Prompt")Return Types
Prompt
Class instances returned by Prompt.create(), Prompt.get(), and Prompt.list(), that provide details about a specific prompt version and additional methods for prompt management.
The Prompt object contains the following properties:
Name of the prompt, which is unique between prompts
Timestamp of when the prompt commit was created
Metadata about the prompt. This could include the first name and last name of the user who created the prompt. For example:
{
"creator_first_name": "John",
"creator_last_name": "Doe",
"creator_email": "john.doe@example.com",
}