Prompt Engineering

Prompt Engineering on Google Cloud is the practice of designing, testing, evaluating, and optimizing prompts for Gemini and related Vertex AI generative models so they produce reliable text, structured, multimodal, audio, video, tool-calling, and agent outputs. In these notebooks, it spans prompt design patterns, controlled generation, evaluation, optimization, grounding, orchestration, safety mitigations, and task-specific workflows on Vertex AI, Agent Platform, and the Gemini API.

Synthesized across 41 notebooks. See the source pages under Notebooks below for line-level grounding.

Prompt engineering starts with clear task framing: specify the goal, required format, allowed context, constraints, examples, and generation parameters. The notebooks repeatedly emphasize concise, specific prompts, one task at a time, low temperature for deterministic extraction/classification/security-sensitive workflows, and explicit grounding when answers must come only from provided context.

For application use, prompts are not treated as static text. They are versioned, templated, evaluated against datasets, compared across prompt variants, constrained with JSON schemas or enums, and optimized with Vertex AI Prompt Optimizer when examples and metrics are available.

The area also extends beyond text. The same discipline applies to multimodal image, video, speech, RAG, tool-use, SQL agents, code refactoring, security guardrails, and evaluation pipelines, with Cloud Storage, BigQuery, LangChain, LlamaIndex, Vertex AI Evaluation, Prompt Management, and Batch Prediction used to operationalize prompt iteration at scale.

Canonical workflow

  1. Define the task, target user outcome, input sources, output format, safety requirements, and whether the answer must be grounded only in provided context.
  2. Choose the appropriate Gemini or Vertex AI model and initialize the Google Cloud project, location, authentication, and required APIs.
  3. Write a concise prompt or system instruction with explicit constraints, examples when useful, and generation parameters suited to the task.
  4. Constrain outputs for application use with response_mime_type, response_schema, response_json_schema, enums, closed vocabularies, or parser format instructions.
  5. Test on a small representative input before scaling to batch prediction, RAG, agents, multimodal files, or optimization jobs.
  6. Evaluate against ground truth, rubrics, custom metrics, human ratings, or built-in Vertex AI Gen AI Evaluation metrics using consistent datasets and model settings.
  7. Compare prompt variants, inspect explanations and raw outputs, then optimize with Vertex AI Prompt Optimizer or manual prompt iteration.
  8. Promote the selected prompt through prompt management, store traceability metadata, monitor cost and quotas, and clean up billable resources created during experimentation.

Best practices

See Prompt Engineering - Best Practices for the full distilled guide.

  • Be concise, specific, grammatically clear, and ask one task at a time.
  • Use system instructions to set durable behavior, guardrails, persona boundaries, output restrictions, and source-of-truth rules.
  • Use zero-shot, one-shot, or few-shot prompting intentionally; keep examples representative and avoid overloading the prompt with too many examples.
  • For grounded Q&A, extraction, RAG, and agents, explicitly instruct the model to use provided context, retrieved documents, tools, or visible evidence instead of prior knowledge.
  • Use low temperature or temperature 0 for deterministic classification, extraction, SQL generation, medical coding, security demonstrations, and repeatable evaluations.
  • For structured outputs, set response_mime_type to application/json and use response_schema, response_json_schema, Pydantic schemas, enums, or closed vocabularies where appropriate.

Key models & APIs

  • gemini-2.5-flash, gemini-2.0-flash, gemini-3.5-flash, gemini-3.1-pro-preview, gemini-3.1-flash-lite, gemini-3.1-flash-tts-preview, gemini-embedding-001, text-embedding-005, google/text-embedding-005, Vertex AI Gemini API and google-genai SDK, Vertex AI Gen AI Evaluation SDK, EvalTask, CustomMetric, and rubric metrics, Vertex AI Prompt Optimizer, Gemini Batch Prediction API, Vertex AI Prompt Management, LangChain and LlamaIndex integrations, Vertex AI Vector Search, BigQuery and BigQuery DataFrames ML, Cloud Storage, Cloud DLP and Cloud Natural Language API, Veo 3.1 video generation models, Vertex AI MaaS reasoning models through the OpenAI SDK

Notebooks (41)

Audio (1)

Gemini (34)

Open Models (2)

Vertex AI Search (1)

Tools (1)

Vision (1)

Workshops (1)


Part of the Generative AI Google Brain · Prompt Engineering - Best Practices