This code sample shows how to build a parameterized prompt template to generate content with multiple variable sets.

## Code sample

### Python


Before trying this sample, follow the Python setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/aiplatform/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    import https://docs.cloud.google.com/python/docs/reference/vertexai/latest
    from vertexai.preview.prompts import https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai._genai.types.Prompt.html

    # Initialize vertexai
    https://docs.cloud.google.com/python/docs/reference/vertexai/latest.init(project=PROJECT_ID, location="us-central1")

    variables = [
        {"animal": "Eagles", "activity": "eat berries"},
        {"animal": "Coyotes", "activity": "jump"},
        {"animal": "Squirrels", "activity": "fly"}
    ]

    # define prompt template
    prompt = Prompt(
        prompt_data="Do {animal} {activity}?",
        model_name="gemini-2.0-flash-001",
        variables=variables,
        system_instruction="You are a helpful zoologist"
        # generation_config=generation_config, # Optional
        # safety_settings=safety_settings, # Optional
    )

    # Generates content using the assembled prompt.
    responses = []
    for variable_set in prompt.variables:
        response = prompt.https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai.preview.generative_models.GenerativeModel.html#vertexai_preview_generative_models_GenerativeModel_generate_content(
            contents=prompt.https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai._genai.types.Prompt.html#vertexai__genai_types_Prompt_assemble_contents(**variable_set)
        )
        https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai._genai.types.EvalCaseDict.html#vertexai__genai_types_EvalCaseDict_responses.append(response)

    for response in responses:
        print(response.text, end="")

    # Example response
        # Assembled prompt replacing: 1 instances of variable animal, 1 instances of variable activity
        # Eagles are primarily carnivorous.  While they might *accidentally* ingest a berry......

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=generativeaionvertexai).