Skip to content

vertexai.preview.prompts.get() does not populate version_id or version_name when fetching latest version #6637

@crashCoder

Description

@crashCoder

Environment details

  • OS: Linux (Debian, x86-64)
  • Python version: 3.13.5
  • pip version: pip show pip → 24.x
  • google-cloud-aiplatform version: 1.148.1

Steps to reproduce

  1. Create a prompt in Vertex AI with at least one version via vertexai.preview.prompts.create_version()
  2. Fetch it without pinning a version: prompts.get(prompt_id="")
  3. Inspect prompt.version_id and prompt.version_name

Code example

import vertexai                                                                                                                                           
from vertexai.preview import prompts
                                                                                                                                                          
vertexai.init(project="my-project", location="us-central1")                                                                                               
                                                                                                                                                          
# Fetch latest — content is correct, but version is unknown                                                                                               
prompt = prompts.get(prompt_id="123456789")
print(prompt.prompt_data)   # ✓ correct content                                                                                                           
print(prompt.version_id)    # None  ← expected: e.g. "3"                                                                                                  
print(prompt.version_name)  # None  ← expected: e.g. "abc123"               

Pinned fetch works correctly

prompt_pinned = prompts.get(prompt_id="123456789", version_id="3")                                                                                        
 print(prompt_pinned.version_id)    # "3"   ✓                                                                                                              
 print(prompt_pinned.version_name)  # "abc123" ✓             

Stack trace

No exception is raised. The fields are silently None.

Root cause

In vertexai/prompts/_prompt_management.py, get() unconditionally assigns the caller-supplied argument back to the object:

prompt._version_id = version_id # always None when no version_id passed

_version_name is never set on this path

The underlying _get_prompt_resource() calls GetDataset, whose response carries no version pointer. _version_name is never set anywhere in the latest-fetch
path.

Compare with _get_prompt_resource_from_version(), which correctly calls get_dataset_version() and sets both fields.

Related: #6193 describes the symmetric bug — get_version() returns the wrong content for a pinned version.

Workaround

raw = prompts.get(prompt_id=prompt_id)                                                                                                                    
versions = prompts.list_versions(prompt_id=prompt_id)                                                                                                     
if versions:                                                                                                                                              
    latest = max(versions, key=lambda v: int(v.version_id))                                                                                               
    raw._version_id = latest.version_id                                                                                                                   
    raw._version_name = latest.display_name            

Works but costs an extra paginated ListDatasetVersions call per fetch.

Possible fix

In _get_prompt_resource(), after get_dataset, issue a list_dataset_versions with page_size=1 to get the latest version metadata:


  versions = prompt._dataset_client.list_dataset_versions(parent=name, page_size=1)
  for version in versions:                                                                                                                                  
      prompt._version_id = version.name.split("/")[-1]
      prompt._version_name = version.display_name                                                                                                           
      break

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