Skip to content

get_version returns latest prompt content instead of specified version content #6193

@apc-shogo-naka

Description

@apc-shogo-naka

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

  1. Create a prompt with initial content (e.g., "Version 1 content")
  2. Create a new version with different content (e.g., "Version 2 content")
  3. Repeat step 2 to create multiple versions
  4. Call get_version(prompt_id="...", version_id="1") to retrieve version 1
  5. 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:

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 prompt

Affected Code

  • Prompts.get_version (sync version): lines 1145-1175
  • AsyncPrompts.get_version (async version): lines 2311-2341

Environment

  • vertexai SDK version: 1.130.0
  • Python version: 3.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: vertex-aiIssues related to the googleapis/python-aiplatform API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions