One-Shot Prompts

One-shot prompts provide a single example alongside your request. Show, don't tell — the model learns pattern, format, and tone from that one example.

March 30, 20265 min read3 / 5

When zero-shot prompts don't give you the right format, tone, or style — add one example. That's it. One carefully chosen example can completely transform your output.

What One-Shot Means

One-shot prompting = one example alongside your request. The model learns the pattern, format, and style from that example and applies it to your new task.

Think of it like pair programming. If you want a junior engineer to create a new API endpoint, you can describe what you want — or you can show them an existing endpoint and say "build something like this." The second approach almost always produces better results, because they have real prior art to reference.

Same principle applies to LLMs.

"Show, don't tell."

When to Use One-Shot

Use one-shot prompting when:

  • You care about a specific format for the output
  • The task involves style or tone matching (blog posts, documentation, etc.)
  • Zero-shot keeps producing outputs that are close but miss something about the structure
  • You want to provide "prior art" from your codebase for the model to follow

Example 1: Content Writing

Without one-shot (zero-shot):

Plain text
Write an engaging introduction for a blog post about remote work productivity.

You get something generic. The model uses its default "blog intro" pattern.

With one-shot:

Plain text
Write an engaging introduction for a blog post about remote work productivity. Example (blog post about morning exercise): "Picture this: It's 6 a.m. Your alarm goes off. And instead of hitting snooze, you lace up your sneakers. Sound impossible? Here's the thing: those who exercise before breakfast report 23% higher energy levels throughout their workday." Now write an introduction for: remote work productivity tips.

Output (actual model result):

"Picture this: you're working from home in your pajamas, coffee in hand, when you realize it's 3:30 p.m. and you've accomplished exactly one load of laundry. Sound familiar? Here's the thing: remote workers who implement just three key productivity strategies report completing their tasks 40% faster than their office-bound counterparts..."

The model picked up the exact structure:

  • Relatable opening scenario
  • A twist ("Sound impossible?" → "Sound familiar?")
  • A statistic as the payoff

One example. That's all it took.

Example 2: Movie Recommendations

Plain text
Recommend a movie based on these viewing preferences. Example: User likes: Inception, The Matrix, Interstellar Recommendation: Arrival (2016) — cerebral sci-fi that rewards patient viewers with a profound twist on time and language. Now recommend for: User likes: The Grand Budapest Hotel, Amélie, The Secret Life of Walter Mitty

Output:

"Based on your love of whimsical, visually stunning films with quirky characters and heartfelt storytelling, I'd recommend Midnight in Paris (2011)..."

The model generalized the pattern: analyze the taste → identify the common theme → recommend something that fits.

One-Shot for Code: Using Prior Art

This is where one-shot prompting is most powerful for developers.

Instead of describing how you want an API endpoint structured, paste an existing one:

Plain text
Add a new API endpoint that fetches a user's order history. Follow the exact same pattern as this existing endpoint: [paste an existing endpoint from your codebase] The new endpoint should: - Route: GET /users/:id/orders - Return: array of orders with id, date, total, status - Use the same error handling and response format

The model now has real prior art from your codebase. The output will match your conventions — your error handling, your response shape, your naming style — without you having to describe all of that explicitly.

Choosing the Right Example

The example you choose matters. Guidelines:

  • Use the general case, not an edge case. The model generalizes from what you show it — if your example is unusual, the output will be unusual too.
  • Include every element you want in the output. If your JSON needs 5 fields, make sure your example has all 5 fields.
  • Don't use an overly complex example — it will generalize the complexity as the pattern.
  • Add brief clarifications if any part of the example might be ambiguous.
Plain text
❌ Poor example choice (edge case): "Here's an example of an error response:" [shows a retry-with-backoff flow] → Model will try to add retry logic to everything ✅ Good example choice (general case): "Here's an example of a success response:" [shows the standard happy path] → Model generalizes the pattern correctly

One-Shot for Planning, Not Just Building

One-shot prompting isn't just for generating code. It's excellent for generating plans first.

Here's a technique: use a one-shot prompt to ask the model to analyze a feature and create an implementation plan — before writing any code.

Plain text
You are helping develop a Prompt Library application. Here's an example of how to analyze and implement a new feature: Example feature: Add a favorites/bookmarking system --- User story: As a user, I want to mark prompts as favorites so I can quickly access my most used prompts. Technical requirements: - Add a heart icon to each prompt card - Store favorite status in localStorage - Create a filter to show only favorites - Visual indicator: filled vs outline icon Code structure: - Data model: add `isFavorite: boolean` to prompt schema - Functions: toggleFavorite(id), filterFavorites(), renderFavoriteIcon() UX considerations: - Place icon in top-right corner of card - Use intuitive icon (heart or star) - Provide visual feedback on click --- Now analyze this feature request using the same format: Add a 5-star rating component to rate prompt effectiveness.

This gives you a full plan to review and refine before any code runs. Then once you're happy with the plan, a simple follow-up prompt implements it:

Plain text
This looks good. Implement this in plain HTML, CSS, and JavaScript.

Practice: Try It Yourself

Exercise 1: Style matching

Write an example of a commit message in your preferred style, then ask the model to generate commit messages in that style for a list of changes.

Exercise 2: Code prior art

Take an existing function from a project you're working on. Paste it as a one-shot example and ask the model to write a similar function for a related task. Compare how well it follows your conventions versus a plain zero-shot request.

Exercise 3: Blog intro cloning

Find a blog introduction you like. Use it as a one-shot example and ask the model to write a new blog intro on a different topic in the same style.

Enjoyed this? Get more like it.

Deep dives on system design, React, web development, and personal finance — straight to your inbox. Free, always.