Intermediate

Gemini Prompting Guide

Master effective prompting for Gemini. Learn to craft multimodal prompts, generate structured output, use system instructions, and leverage grounding with Google Search.

Prompting Fundamentals

Good prompts give Gemini clear direction. The quality of your output depends heavily on how you structure your input. Here are the core principles:

  1. Be Specific

    Tell Gemini exactly what you want, including the format, length, tone, and audience. Vague prompts produce vague results.

  2. Provide Context

    Give background information that helps Gemini understand your situation. The more relevant context, the better the output.

  3. Define the Output Format

    Specify whether you want a list, table, code, JSON, markdown, or prose. Gemini follows formatting instructions well.

  4. Iterate and Refine

    Start with a basic prompt, review the output, and refine your instructions. Gemini works best with iterative improvement.

Basic vs. Effective Prompts

Weak Prompt
// Too vague - Gemini has to guess what you want
Tell me about Python.
Strong Prompt
// Specific, structured, and actionable
I'm a JavaScript developer learning Python.
Create a comparison guide covering:

1. Variable declaration and types
2. Functions and arrow function equivalents
3. Array/list methods
4. Object/dictionary handling
5. Async/await patterns

For each topic, show the JavaScript code side-by-side
with the Python equivalent. Keep explanations brief
and focus on practical differences.

Multimodal Prompts

One of Gemini's unique strengths is its ability to process multiple types of input simultaneously. Here are patterns for effective multimodal prompting:

Text + Image

Image Analysis Prompt
# Upload an image of a UI design, then:

Analyze this UI design and provide:

1. Accessibility issues - Any WCAG violations
2. UX improvements - Layout and flow suggestions
3. Code skeleton - HTML/CSS structure to implement this

Rate the overall design quality from 1-10 with
specific reasoning.

Text + Video

Video Analysis Prompt
# Upload a video file or provide a YouTube link:

Watch this video and create:

1. A timestamped summary of key points
2. A list of action items mentioned
3. Any questions left unanswered

Format as a structured meeting notes document.

Text + Multiple Images

Comparison Prompt
# Upload two product photos:

Compare these two products based on:
- Design and build quality (from the images)
- Apparent features visible in each
- Which looks more professional/premium

Present your comparison as a table with ratings.
Multimodal tip: When combining images with text, always reference the image explicitly in your prompt. Say "In the uploaded image..." or "Looking at this screenshot..." so Gemini knows to analyze the visual content alongside your text instructions.

Structured Output

Gemini can generate output in specific formats when instructed. This is especially useful for programmatic consumption:

JSON Output

JSON Generation Prompt
Extract the following information from this product
review and return it as valid JSON:

{
  "sentiment": "positive" | "negative" | "mixed",
  "rating": 1-5,
  "pros": ["list of positives"],
  "cons": ["list of negatives"],
  "summary": "one sentence summary",
  "would_recommend": true | false
}

Review: "I bought this laptop last month and I'm
mostly happy with it. The screen is gorgeous and
the keyboard feels great. However, the battery life
is disappointing - barely 5 hours. For the price,
I expected more. Still, I'd recommend it if you're
mostly near an outlet."

System Instructions

System instructions set the overall behavior and persona for Gemini. They are available in Google AI Studio and the API:

System Instruction Example
// System instruction (set in AI Studio or API):

You are a senior software architect with 15 years
of experience in distributed systems. When reviewing
code or architecture:

- Always consider scalability and reliability
- Point out potential single points of failure
- Suggest monitoring and observability improvements
- Use industry standard terminology
- Provide concrete examples, not abstract advice
- Rate severity of issues: Critical, Warning, Info

Few-Shot Examples

Providing examples of desired input-output pairs helps Gemini understand exactly what you want:

Few-Shot Prompt
Convert these natural language descriptions into
SQL queries for a PostgreSQL database.

Example 1:
Input: "Show all users who signed up last month"
Output: SELECT * FROM users
        WHERE created_at >= DATE_TRUNC('month',
        CURRENT_DATE - INTERVAL '1 month')
        AND created_at < DATE_TRUNC('month',
        CURRENT_DATE);

Example 2:
Input: "Count orders by status"
Output: SELECT status, COUNT(*) as order_count
        FROM orders
        GROUP BY status
        ORDER BY order_count DESC;

Now convert:
Input: "Find the top 10 customers by total spending
in the last quarter, including their email addresses"

Grounding with Google Search

Gemini can ground its responses in real-time Google Search results, providing up-to-date information with source citations:

💡
What is grounding? Grounding connects Gemini's responses to real-world data sources. When grounding is enabled, Gemini can search the web to verify facts, find current information, and cite sources — reducing the risk of hallucination.
Grounding-Friendly Prompt
# This works best with grounding enabled in the API:

What are the latest developments in quantum computing
as of this month? Include:

1. Recent breakthroughs or announcements
2. Key companies and their progress
3. Practical applications being explored

Cite your sources for each point.

Enabling Grounding via API

Python
import google.generativeai as genai

genai.configure(api_key="YOUR_API_KEY")

model = genai.GenerativeModel('gemini-pro')

# Enable grounding with Google Search
response = model.generate_content(
    "What are today's top tech news stories?",
    tools=[genai.Tool(google_search=genai.GoogleSearch())]
)

print(response.text)

💡 Try It: Build a Multimodal Prompt

Go to gemini.google.com and try this exercise: Upload a screenshot of any website, then ask Gemini to analyze the design and suggest three specific improvements. Compare the response quality when you give detailed instructions vs. a simple "What do you think?"

Notice how specific instructions about format and criteria produce more actionable feedback.