-
Notifications
You must be signed in to change notification settings - Fork 417
Description
Description
Bug Description
The get_version method in Prompts class (and AsyncPrompts) always returns the latest prompt content regardless of which version_id is specified. This is because the method creates the Prompt object from prompt_dataset_resource (which contains the latest prompt data) instead of prompt_version_resource (which contains the version-specific data).
Steps to Reproduce
- Create a prompt with initial content (e.g., "Version 1 content")
- Create a new version with different content (e.g., "Version 2 content")
- Repeat step 2 to create multiple versions
- Call
get_version(prompt_id="...", version_id="1")to retrieve version 1 - The returned prompt contains "Version 2 content" (latest) instead of "Version 1 content"
Expected Behavior
get_version should return the prompt content corresponding to the specified version_id.
Actual Behavior
get_version always returns the latest prompt content, ignoring the version_id parameter for the prompt data.
Root Cause
In vertexai/_genai/prompts.py, the get_version method creates the Prompt object from prompt_dataset_resource:
python-aiplatform/vertexai/_genai/prompts.py
Lines 1145 to 1175 in 47be102
| def get_version( | |
| self, | |
| *, | |
| prompt_id: str, | |
| version_id: str, | |
| config: Optional[types.GetPromptConfig] = None, | |
| ) -> types.Prompt: | |
| """Gets a prompt resource from a Vertex Dataset. | |
| Args: | |
| prompt_id: The id of the Vertex Dataset resource containing the prompt. For example, if the prompt resource name is "projects/123/locations/us-central1/datasets/456", then the prompt_id is "456". | |
| version_id: The id of the Vertex Dataset Version resource containing the prompt version. For example, if the prompt version resource name is "projects/123/locations/us-central1/datasets/456/datasetVersions/1", then the version_id is "1". | |
| config: Optional configuration for getting the prompt. | |
| Returns: | |
| A types.Prompt object representing the prompt with its associated Dataset and Dataset Version resources. | |
| """ | |
| prompt_dataset_resource = self._get_dataset_resource(name=prompt_id) | |
| prompt = _prompt_management_utils._create_prompt_from_dataset_metadata( | |
| prompt_dataset_resource, | |
| ) | |
| prompt._dataset = prompt_dataset_resource | |
| prompt_version_resource = self._get_dataset_version_resource( | |
| dataset_id=prompt_id, | |
| dataset_version_id=version_id, | |
| ) | |
| prompt._dataset_version = prompt_version_resource | |
| return prompt |
Suggested Fix
The Prompt object should be created from prompt_version_resource instead:
# Proposed fix
prompt_dataset_resource = self._get_dataset_resource(name=prompt_id)
prompt_version_resource = self._get_dataset_version_resource(
dataset_id=prompt_id,
dataset_version_id=version_id,
)
prompt = _prompt_management_utils._create_prompt_from_dataset_metadata(
prompt_version_resource, # ← Use version-specific resource
)
prompt._dataset = prompt_dataset_resource
prompt._dataset_version = prompt_version_resource
return promptAffected Code
Prompts.get_version(sync version): lines 1145-1175AsyncPrompts.get_version(async version): lines 2311-2341
Environment
- vertexai SDK version: 1.130.0
- Python version: 3.13.2