Skip to content

Blog

Think Before You Answer

Think Before You Answer: Chain of Thought Prompting for Better Results

Introduction: The Problem with Direct Questions and Answers

Large language models (LLMs) like Gemini are powerful, but direct questions can lead to incorrect or vague answers, especially for complex tasks. For example, the white paper shows that asking an LLM to solve “What is the age difference if my partner is 20 years older, but 3 years have passed?” can result in errors due to the model’s reliance on pattern recognition rather than reasoning. Chain of Thought (CoT) prompting solves this by guiding the AI to “think” step-by-step, improving accuracy and transparency.

What is Chain of Thought (CoT) Prompting?

CoT prompting encourages LLMs to generate intermediate reasoning steps before providing a final answer. According to the white paper, this mimics human problem-solving by breaking down complex tasks into logical steps. For instance, instead of directly answering a math problem, the AI explains each step, reducing errors and making the process interpretable.

When to Use Reasoning Chains

CoT is ideal for tasks requiring logical reasoning, such as:

  • Mathematical Problems: Solving equations or calculating differences, as shown in the white paper’s example of age calculations.
  • Logic Puzzles: Deductive reasoning tasks, like determining the order of events.
  • Complex Decision-Making: Evaluating options, such as choosing a business strategy.

Simple Examples Contrasting Direct Questions vs. CoT Approach

The white paper illustrates the difference with a math problem:

  • Direct Prompt: “What is the age difference if my partner is 20 years older, but 3 years have passed?”
    • Output: “17” (incorrect, as the model may miscalculate).
  • CoT Prompt: “Calculate the age difference step-by-step: My partner is 20 years older. After 3 years, both our ages increase by 3. Explain each step.”
    • Output: “Step 1: Initial difference is 20 years. Step 2: After 3 years, both ages increase by 3, so the difference remains 20 years. Final answer: 20.”

The CoT approach ensures the AI reasons through the problem, catching errors like subtracting the 3 years incorrectly.

How to Construct Effective Reasoning Prompts

  1. Instruct Step-by-Step Reasoning: Use phrases like “Explain each step” or “Break down the problem.”
  2. Use Examples (Few-Shot CoT): Provide a sample problem with reasoning steps, as shown in the white paper’s Table 13, where a single-shot CoT prompt improves the response.
  3. Set Temperature to 0: The white paper recommends a temperature of 0 for CoT to ensure deterministic, logical outputs.
  4. Test and Refine: Run the prompt in Vertex AI Studio and adjust based on the output’s clarity and accuracy.

Real-World Applications for Everyday Users

  • Personal Finance: Calculate loan payments by breaking down principal, interest, and terms.
  • Project Planning: List steps to complete a task, like organizing an event.
  • Troubleshooting: Diagnose tech issues by reasoning through symptoms and solutions.

For example, a CoT prompt like “List the steps to plan a budget for a vacation, including flights, accommodation, and activities” ensures a detailed, logical plan.

Conclusion: Getting AI to Show Its Work Improves Results

Chain of Thought prompting transforms AI from a black-box answer generator into a transparent reasoning tool. By encouraging step-by-step logic, CoT improves accuracy for math, logic, and decision-making tasks. Try it with everyday problems like budgeting or planning, and use tools like Vertex AI Studio to refine your prompts. Showing its work makes AI more reliable and useful.

The Art of Temperature

The Art of Temperature: How to Control AI Creativity and Accuracy

Introduction: The Balancing Act Between Creativity and Precision

Crafting the perfect prompt is only half the battle when working with large language models (LLMs). The other half lies in fine-tuning how the model responds—finding that sweet spot between creativity and precision. Enter the temperature setting: a powerful configuration that controls the randomness of an AI’s output.

Whether you need factual, consistent responses for data analysis or imaginative, out-of-the-box ideas for creative projects, understanding temperature—along with its companions Top-K and Top-P sampling—is your key to getting exactly the results you want.

What is Temperature in AI Models?

Temperature is the control knob that governs how predictable or surprising your AI’s responses will be. When LLMs generate text, they predict probabilities for each possible next word (or token). Temperature determines how the model chooses from these options.

Picture it as a creativity dial on your dashboard. Turn it down toward zero, and your AI becomes a careful, methodical assistant that always picks the most likely next word. This produces predictable, focused outputs perfect for technical tasks. Crank it up toward one or higher, and suddenly your AI becomes an adventurous collaborator, exploring unexpected word choices that lead to surprising, diverse results.

The Google Prompt Engineering White Paper explains this beautifully: low temperature favors deterministic responses, while high temperature embraces randomness and creativity.

When to Use Different Temperature Settings

The right temperature depends entirely on what you’re trying to accomplish. Here’s how to match your settings to your goals:

Low Temperature (0–0.3): The Precision Zone Perfect for tasks where accuracy matters most. At temperature 0 (called “greedy decoding”), your model becomes utterly predictable, always choosing the most probable token. This makes it ideal for math problems, code generation, or data extraction where there’s only one correct answer. When classifying movie reviews as positive or negative, for instance, low temperature ensures your model follows clear, reliable logic every time.

Medium Temperature (0.4–0.7): The Goldilocks Zone This balanced range works beautifully for conversational blog posts, summaries, or any task where you want engaging yet reliable output. The white paper suggests starting around 0.2 for coherent but slightly creative results—perfect when you need your AI to be both trustworthy and interesting.

High Temperature (0.8–1.0): The Creative Playground Break out the high temperatures for storytelling, brainstorming sessions, or generating novel ideas. Here, your model explores less likely word choices, leading to unexpected and diverse outputs that can surprise even you. Be warned though: temperatures above 1 can make all word choices equally likely, which might be too chaotic for practical use (though it can be fun for experimental creative writing).

Real-World Examples: Same Prompt, Different Personalities

Let’s see temperature in action with a single prompt: “Generate a storyline for a first-person video game.”

At Low Temperature (0.1): Your AI delivers a straightforward, reliable storyline—perhaps a linear narrative about a hero rescuing a village from bandits. The output stays close to proven gaming formulas, with minimal embellishment but maximum clarity.

At Medium Temperature (0.4): The storyline gains personality. Maybe your hero faces a moral dilemma about whether to save the village or pursue the bandits to their hidden treasure. The output remains coherent but includes creative twists that make the story more compelling.

At High Temperature (0.9): Now things get wild. Your storyline might feature time-traveling aliens, a world where gravity randomly reverses, or a hero who discovers they’re actually the villain’s lost sibling. Imaginative? Absolutely. Practical for game design? That depends on your project’s goals.

These examples show how temperature shapes your AI’s creative voice, from reliable consultant to bold collaborator.

Beyond Temperature: Your Supporting Cast of Controls

Temperature doesn’t work alone. Two other sampling methods fine-tune your AI’s behavior:

Top-K Sampling acts like a filter, selecting only the K most likely tokens from the model’s predictions. Set K to 20, and your model considers only the 20 most probable next words, keeping things factual. Bump it to 40, and you’re allowing more creative possibilities. Think of it as expanding or narrowing your AI’s vocabulary for each decision.

Top-P Sampling (Nucleus Sampling) takes a different approach, selecting the smallest group of tokens whose combined probability exceeds your threshold P. Set P to 0.9, and your model considers only the most likely words until their probabilities add up to 90%. This keeps output focused while adapting to each situation’s unique probabilities.

The white paper suggests these starting combinations: Top-K of 30 and Top-P of 0.95 with temperature 0.2 for balanced results, or Top-K of 40 and Top-P of 0.99 with temperature 0.9 for maximum creativity.

Choosing Your Perfect Settings

Selecting the right combination feels like mixing the perfect cocktail—each ingredient affects the others. Here’s your practical mixing guide:

For Factual Tasks (math, code debugging, data extraction): Temperature 0, Top-K 20, Top-P 0.9. Your AI becomes a precise, reliable assistant that sticks to proven solutions.

For Balanced Tasks (blog writing, summarization, general conversation): Temperature 0.4, Top-K 30, Top-P 0.95. This creates an engaging collaborator that’s both creative and trustworthy.

For Creative Tasks (storytelling, brainstorming, experimental writing): Temperature 0.9, Top-K 40, Top-P 0.99. Your AI transforms into an imaginative partner ready to explore uncharted territory.

Remember that extreme values can override others—temperature 0 makes Top-K and Top-P irrelevant since the model always picks the most probable token anyway. Start with the suggested values, then experiment based on your results.

The white paper’s examples demonstrate this perfectly: code generation tasks use low temperature to ensure functional, well-documented output, while creative storyline generation benefits from higher temperature settings that encourage novel ideas.

Conclusion: Your Temperature Toolkit

Mastering temperature and sampling controls transforms you from someone who asks AI questions into someone who conducts AI conversations. These settings are your instruments for orchestrating exactly the kind of response your project needs.

Start with the white paper’s balanced baseline—temperature 0.2, Top-K 30, Top-P 0.95—then adjust based on your specific goals. Building a financial model? Turn down the temperature. Writing your next novel? Crank it up. Extracting data from reports? Keep it low and steady.

The key is experimentation. Test your prompts, document what works, and build your own playbook of settings for different tasks. With practice, you’ll develop an intuitive sense for when your AI needs to be a careful analyst versus a creative collaborator.

Temperature isn’t just a technical setting—it’s your creative control panel for unlocking exactly the kind of AI partnership your work demands.

Prompt Engineering 101 - The Beginner's Guide to Talking with AI

Introduction: What is Prompt Engineering and Why It Matters

Prompt Engineering 101

Prompt engineering is both an art and a science—the craft of designing inputs that guide AI language models toward producing your desired outputs. Whether you’re asking an AI to write a story, solve a math problem, or classify an email, the quality of your prompt directly impacts the quality of the response you receive. As AI researcher Lee Boonstra highlights in her white paper on prompt engineering, while anyone can write a prompt, creating truly effective ones requires understanding how language models work and embracing an experimental mindset. This guide will introduce you to the fundamentals, helping you converse with AI more effectively.

Understanding How LLMs Work: The Basics

At their core, large language models (LLMs) function as sophisticated prediction engines. They take your text prompt and predict what should come next, based on patterns learned from massive training datasets. Think of it as an incredibly advanced version of your phone’s text prediction feature—except instead of suggesting the next word, an LLM can generate paragraphs, essays, or code.

The model works by predicting one token (a word or character) at a time, then adding that prediction to your original input before making the next prediction. This creates a flowing, coherent response. However—and this is crucial—the quality of that response depends heavily on how clearly you frame your prompt. Vague or poorly structured prompts often lead to ambiguous or incorrect outputs. Understanding this predictive nature is your first step toward crafting prompts that guide the AI toward accurate, relevant responses.

Basic Prompting Techniques for Beginners

Let’s explore three foundational prompting techniques that will help you communicate effectively with AI language models.

Zero-Shot Prompting: Just Ask What You Want

Zero-shot prompting is exactly what it sounds like—providing a task description without examples and letting the AI figure it out. For instance:

“Classify this movie review as positive or negative: ‘This film was a disturbing masterpiece’”

This approach relies on the model’s pre-existing knowledge to make a prediction. Zero-shot prompts work best for straightforward tasks, but they may struggle with nuanced inputs like our example above, where “disturbing” and “masterpiece” create semantic tension. For best results, keep your zero-shot prompts clear, specific, and unambiguous.

One-Shot and Few-Shot: Teaching by Example

When zero-shot prompts aren’t cutting it, one-shot and few-shot prompting can provide the clarity you need by including examples. A one-shot prompt provides a single example, while a few-shot prompt offers multiple examples (typically three to five) to establish a pattern. For instance:

Review: "Loved every minute!" → Positive
Review: "Boring and predictable." → Negative
Review: "A thrilling ride!" → Positive
Classify: "This film was a disturbing masterpiece."

By demonstrating the task with clear examples, you’re essentially teaching the AI what you expect. For best results, use high-quality, diverse examples that capture the nuances of your task and help the model handle edge cases effectively.

Simple Instructions vs. Complex Prompts

Beginners often fall into the trap of overcomplicating their prompts, but simplicity is generally more effective. Use clear, concise instructions with action-oriented verbs like “describe,” “classify,” or “generate.”

For example, instead of a vague prompt like: “I’m in New York with kids, where should we go?”

Try this more specific approach: “Act as a travel guide and describe three family-friendly attractions in Manhattan suitable for a 3-year-old.”

Simple, direct instructions reduce confusion and ensure the AI focuses precisely on what you need.

Practical Examples: Before and After Prompt Improvements

To demonstrate the power of well-crafted prompts, let’s examine two examples showing how improved prompts yield better results.

Example 1: Blog Post Generation

Before: “Write a blog post about video game consoles.”

Issue: This prompt is too vague, likely leading to generic content without clear focus or audience.

After: “Generate a 3-paragraph blog post about the top 5 video game consoles of the past decade, written in a conversational style for casual gamers. Include what made each console distinctive.”

Why It Works: The improved version specifies length, subject focus, time period, style, audience, and content expectations. These constraints guide the AI toward producing a focused, engaging post tailored to your needs.

Example 2: Code Explanation

Before: “What does this code do?”

Issue: This lacks context and forces the model to guess at the code’s purpose and your level of expertise.

After: “Explain this Bash script line by line, assuming I’m a beginner learning to code. Focus on the purpose of each command.”

Why It Works: The revised prompt clarifies the desired depth of explanation, your knowledge level, and specific aspects to focus on, ensuring you receive a useful, educational response.

These examples illustrate an important principle: specific, well-structured prompts consistently produce more accurate and useful outputs.

Common Beginner Mistakes to Avoid

Watch out for these common pitfalls that can limit the effectiveness of your prompts:

Being Too Vague: Prompts like “Tell me about AI” are simply too broad, leading to unfocused responses. Instead, narrow the scope: “Summarize three recent breakthroughs in AI medical diagnostics in 150 words or less.”

Overloading with Constraints: Listing what not to do (e.g., “Don’t use technical jargon, don’t be too long, don’t be boring”) can confuse the model. Focus instead on positive instructions: “Write a concise, engaging summary using everyday language.”

Ignoring Examples: Skipping examples in one-shot or few-shot prompts can reduce accuracy, especially for complex tasks like text classification or code generation.

Not Testing Iteratively: Prompt engineering is fundamentally iterative. If you don’t tweak and test your prompts, you’ll miss opportunities to improve your results.

By avoiding these mistakes, you’ll save time and get substantially better results from your AI interactions.

Tips for Getting Started with Your First Prompts

Ready to begin your prompt engineering journey? Here are practical tips to craft effective prompts:

Start Simple: Begin with zero-shot prompts for basic tasks, like “Summarize this paragraph in one sentence” or “Generate five ideas for blog topics about sustainable gardening.”

Add Examples as Needed: If your initial results aren’t what you expected, try adding one or more examples to demonstrate the pattern you want the AI to follow.

Experiment with Parameters: Many AI platforms allow you to adjust settings like “temperature” (which controls randomness). Set temperature low (around 0) for factual or deterministic tasks like math problems, and higher (0.7-0.9) for creative tasks like storytelling.

Document Your Attempts: Keep track of your prompts, settings, and results to learn what works best for different types of tasks. A simple spreadsheet can be invaluable for this purpose.

Be Specific About Format and Style: Clearly state your desired output format, tone, style, or length: “Write a 50-word product description for a smartwatch in an enthusiastic tone, highlighting its fitness tracking capabilities.”

Iterate and Refine: Test different wordings or structures, and don’t hesitate to revise based on the AI’s output. Each iteration brings you closer to mastery.

Conclusion: The Iterative Nature of Prompt Engineering

Prompt engineering is a skill that improves with practice and experimentation. It’s inherently iterative—you craft a prompt, test it, analyze the results, and refine it until you achieve your desired output. By starting with simple techniques like zero-shot and few-shot prompting, avoiding common mistakes, and following best practices, you’ll quickly learn to communicate effectively with AI.

Whether you’re generating creative content, solving problems, or extracting insights, thoughtful prompt engineering empowers you to unlock the full potential of language models. So grab your keyboard, start experimenting, and discover the remarkable possibilities of conversing effectively with AI.

Prompt Engineering Outline

Introduction: What is Prompt Engineering and Why It Matters

Outlines for Beginners

1. “Prompt Engineering 101: The Beginner’s Guide to Talking with AI”

Outline:

  • Introduction: What is prompt engineering and why it matters
  • Understanding how LLMs work at a basic level (prediction engines)
  • Basic prompting techniques for beginners:
    • Zero-shot prompting: Just ask what you want
    • One-shot and few-shot: Including examples to guide the AI
    • Simple instructions vs. complex prompts
  • Practical examples showing before/after prompt improvements
  • Common beginner mistakes to avoid
  • Tips for getting started with your first prompts
  • Conclusion: The iterative nature of prompt engineering

2. “The Art of Temperature: How to Control AI Creativity and Accuracy”

Outline:

  • Introduction: The balancing act between creativity and precision
  • What is temperature in AI models?
  • When to use different temperature settings:
    • Low temperature (0-0.3): Factual, consistent responses
    • Medium temperature (0.4-0.7): Balanced responses
    • High temperature (0.8-1.0): Creative, diverse outputs
  • Real-world examples comparing the same prompt at different temperatures
  • Other sampling controls: Top-K and Top-P explained simply
  • How to choose the right settings for your specific needs
  • Conclusion: Finding your temperature sweet spot

3. “Role-Playing with AI: How to Use System and Role Prompts”

Outline:

  • Introduction: Getting AI to adopt specific personas
  • The power of context in AI interactions
  • System prompting: Setting the stage for AI behavior
  • Role prompting techniques:
    • How to assign clear roles to the AI
    • Popular roles that improve specific outputs
    • Examples of effective role prompts
  • Contextual prompting: Adding background information
  • A step-by-step guide to creating your first role-based prompt
  • Conclusion: Expanding your prompting toolkit with personas

4. “Think Before You Answer: Chain of Thought Prompting for Better Results”

Outline:

  • Introduction: The problem with direct questions and answers
  • What is Chain of Thought (CoT) prompting?
  • When to use reasoning chains:
    • Mathematical problems
    • Logic puzzles
    • Complex decision-making
  • Simple examples contrasting direct questions vs. CoT approach
  • How to construct effective reasoning prompts
  • Real-world applications for everyday users
  • Conclusion: Getting AI to show its work improves results

5. “Format Matters: How to Get Structured Outputs from AI Models”

Outline:

  • Introduction: The challenge of getting consistent AI outputs
  • Why structure matters in AI responses
  • Techniques for requesting specific formats:
    • JSON and structured data
    • Lists and tables
    • Step-by-step instructions
  • Example prompts that enforce structure
  • How to specify output length and detail level
  • Common formatting issues and how to fix them
  • Conclusion: Better prompts lead to more usable outputs

6. “Prompt Engineering Best Practices: Learn from the Experts”

Outline:

  • Introduction: Moving beyond basic prompting
  • Best practices from Google’s white paper:
    • Be specific about desired outputs
    • Use instructions over constraints
    • Experiment with different formats
    • Document your prompt attempts
  • The iteration process: How to improve prompts systematically
  • Creating a personal prompt library for reuse
  • Tools to help track and improve your prompts
  • Conclusion: Becoming a better prompt engineer through practice

7. “Beyond Text: An Introduction to Multimodal Prompting”

Outline:

  • Introduction: The expanding world of AI inputs
  • What is multimodal prompting?
  • Types of inputs AI can now understand:
    • Text and images together
    • Code with explanations
    • Visual problem-solving
  • Simple examples anyone can try
  • Use cases for everyday multimodal prompting
  • Tips for effective multimodal interactions
  • Conclusion: The future of AI communication

8. “Coding with AI: Effective Prompts for Programming Tasks”

Outline:

  • Introduction: How AI is changing programming workflows
  • Prompt techniques specific to code generation:
    • Writing new code from descriptions
    • Explaining existing code
    • Debugging and reviewing
    • Translating between languages
  • Real examples of coding prompts and outputs
  • Best practices for programming-related prompts
  • Limitations to be aware of
  • Conclusion: Integrating AI into your development process