Techniques to improve gen AI model output · Topic 3 of 5

Prompt Engineering Techniques

Prompt engineering for LLMs: zero-shot, one-shot, few-shot, role prompting, prompt chaining, chain-of-thought and ReAct prompting, with when to use each.

  • 4 min
  • Includes a diagram
In a nutshell
  • Prompt engineering is the cheapest, fastest way to improve output.
  • Zero-shot: no examples. One-shot: one. Few-shot: several.
  • Role prompting sets perspective; prompt chaining splits tasks into steps.

What it is

Prompt engineering is the practice of designing the input to a large language model so that it produces the most useful output. It matters because the same model can give a vague answer or an excellent one depending on the prompt, and prompting is the cheapest and fastest way to improve results: no training, no new data pipeline.

Zero shotinstruction onlyOne shotone exampleFew shotseveral examplesChain of thoughtreason step by stepReActreason and act with tools

How it works

What a good prompt contains

ElementExample
Task"Summarize this complaint."
Context"The reader is a store manager with two minutes."
Constraints"Three bullet points, no more than 60 words."
ExamplesOne or more sample inputs with the desired outputs
Format"Return JSON with fields issue, urgency, next_step."

The basic techniques

TechniqueHow it worksWhen to use it
Zero-shotGive the instruction with no examplesSimple, common tasks the model already understands
One-shotGive one example of input and desired outputShow a specific format or style once
Few-shotGive several examplesWhen consistency matters, or the task or labels are specific to your business
Role promptingAsk the model to act as a role: "You are an experienced compliance officer"Set tone, perspective and level of expertise
Prompt chainingSplit a complex task into steps, feeding each output into the next promptLong or multi-stage work, such as extract, then analyze, then draft
Exam tip

If the model's answers are right but inconsistently formatted, add examples (one-shot or few-shot). If the task is too big for one prompt, chain prompts.

The advanced techniques

TechniqueHow it worksWhen to use it
Chain-of-thought (CoT) promptingAsk the model to reason step by step before giving the answer, or show examples that include the reasoningProblems needing several logical steps: calculations, multi-condition decisions
ReAct promptingShort for Reason and Act: the model alternates between reasoning about what to do, acting (calling a tool, such as a search or an API), and observing the result, until it reaches an answerTasks that need fresh information or actions in other systems, typical of agents

Example of few-shot prompting

Classify each support message as Billing, Technical or Account.
Message: "I was charged twice this month." -> Billing
Message: "The app crashes when I upload a photo." -> Technical
Message: "How do I change my email address?" -> Account
Message: "My invoice shows the wrong plan." ->

The examples teach the labels and the format, so the model answers "Billing" consistently.

Example of the ReAct pattern

The ReAct pattern: for the question whether an order arrives before Friday, the model reasons it needs the order status, acts by calling an order lookup tool, observes a Thursday delivery date, repeats if needed, then answers yes. A customer asks, "Will my order arrive before Friday?" The model reasons that it needs the order status, acts by calling an order lookup tool, observes the expected delivery date, then reasons about the answer and replies. This is how many agents work.

Limits of prompting

Prompting cannot give a model facts it does not have (that needs grounding) and cannot reliably change deeply ingrained behavior at very high volume (that may need tuning). It is the first step, not the only one.

A worked scenario

An insurer's team writes claim summaries. A zero-shot prompt gives uneven results, so they add few-shot examples of good summaries. For complex claims they use prompt chaining: extract facts, then check policy terms, then draft. To decide coverage they ask for chain-of-thought reasoning, and their claims agent uses ReAct to look up policy data before answering. A role prompt sets the tone: "You are a careful claims adjuster."

How the exam asks about this

  • "Provide several examples to get consistent output." Few-shot.
  • "Ask the model to explain its reasoning step by step." Chain-of-thought.
  • "The model reasons, calls a tool, observes the result, and continues." ReAct.
  • "Break a complex task into a sequence of prompts." Prompt chaining.
  • "Tell the model to answer as a financial advisor." Role prompting.

What to remember for the exam

  • Prompt engineering is the cheapest, fastest way to improve output.
  • Zero-shot: no examples. One-shot: one. Few-shot: several.
  • Role prompting sets perspective; prompt chaining splits tasks into steps.
  • Chain-of-thought: step-by-step reasoning. ReAct: reasoning plus tool actions.
  • Prompting cannot add missing facts; grounding does.
Watch out

Few-shot examples teach patterns, including mistakes. Use correct, representative examples.

Common mistakes

Confusing chain-of-thought with prompt chaining. CoT reasons within one answer; chaining links several prompts.

Expecting zero-shot to match a company-specific format. Show examples.

Using ReAct without tools. Its point is acting through tools and observing results.

Check yourself

  • What is few-shot prompting?

    Including several examples of input and desired output in the prompt so the model follows the pattern.

  • What does ReAct stand for and do?

    Reason and Act: the model alternates reasoning with tool actions and observations until it reaches an answer.

  • How does prompt chaining differ from chain-of-thought?

    Prompt chaining splits a task across several prompts; chain-of-thought asks for step-by-step reasoning within one response.

Topic 3 of 5 in Techniques to improve gen AI model output

Test yourself on Techniques to improve gen AI model output

The full Google Cloud Generative AI Leader question bank has 512 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.