preloader
blog post

Prompting Best Practices: Provide Context and Examples

author image

Context Is Everything

AI models are trained on the entire internet, but they don’t know anything about your specific situation. Your codebase, your customers, your constraints—all invisible until you share them.

Context bridges that gap. Examples demonstrate what you want. Together, they transform generic AI into a useful assistant.

Why Context Matters

Without context, AI fills in blanks with assumptions. Those assumptions are often wrong.

Without context: “Why is the test failing?”

AI assumes: Generic test, generic failure. Response: Generic debugging advice.

With context: “This Jest test for our React component fails with ‘TypeError: Cannot read property ‘map’ of undefined’. The component receives an array of users from an API. The test passes when I run it alone but fails in CI. What might cause this?”

AI understands: Specific framework, specific error, specific behavior pattern. Response: Targeted diagnosis of race conditions or mock configuration.

Types of Context to Include

Technical context:

  • Language/framework versions
  • Architecture patterns
  • Dependencies and constraints
  • Error messages (exact text)

Business context:

  • Who the users are
  • What problem you’re solving
  • What constraints exist (time, budget, compatibility)
  • What you’ve already tried

Domain context:

  • Industry-specific terminology
  • Regulatory requirements
  • Conventions and standards

The Context Formula

A good contextual prompt follows this pattern:

[Situation] + [Specific question] + [Relevant constraints]

Example: “We’re a B2B SaaS company [situation] looking to improve our trial-to-paid conversion [specific question]. Our trial is 14 days, and most drop-off happens in the first 3 days. We can’t change the trial length due to sales team requirements [constraints]. What are 5 specific things we could do in the first 3 days to improve engagement?”

Using Examples (Few-Shot Prompting)

Examples are the fastest way to communicate what you want. Show, don’t just tell.

Without examples: “Write error messages for our form validation”

With examples: “Write error messages for our form validation. Match our existing style:

  • Email: ‘Please enter a valid email address’
  • Password: ‘Password must be at least 8 characters’
  • Phone: ‘Please enter a 10-digit phone number’

Now write messages for:

  • Date of birth (must be 18+)
  • Address (required field)
  • Credit card (invalid number)”

The examples establish tone, length, and structure. The AI matches them automatically.

Example Quantity Guidelines

  • 1 example: Establishes basic format
  • 2-3 examples: Shows pattern variation
  • 4-5 examples: Covers edge cases

More isn’t always better. 3 good examples usually suffice.

Negative Examples

Sometimes showing what you don’t want is as valuable as showing what you do.

“Write product copy for our analytics dashboard. Here’s what we want to avoid:

DON’T: ‘Leverage cutting-edge AI-powered insights to synergize your data strategy’

DO: ‘See what’s happening in your business. Understand why. Act on it.’

Write copy for the following features: custom reports, scheduled exports, team sharing.”

Negative examples prevent common mistakes.

Context for Code

When asking about code, include:

The code itself:

def process_users(users):
    return [u.name for u in users if u.active]

The error (if any):

AttributeError: 'dict' object has no attribute 'name'

The expected behavior: “Should return list of names for active users”

The actual behavior: “Crashes when users come from API response”

What you’ve tried: “I tried converting to objects but that seems inefficient”

Context for Writing

When asking for written content:

Audience: Who will read this? Purpose: What should they do after reading? Tone: Professional, casual, technical, friendly? Length: Word count or format constraints Examples: Existing content to match

“Write a changelog entry for our new export feature.

Audience: Technical users and developers Purpose: Inform them about new capability Tone: Professional but friendly, like our existing docs Length: 2-3 sentences

Example from last release: ‘PDF Export now supports custom headers and footers. Add your company logo, page numbers, or custom text to any exported document. Configure defaults in Settings > Export.’

New feature: CSV exports can now include or exclude specific columns.”

When to Update Context

Add context when:

  • You get a generic response
  • The AI makes wrong assumptions
  • The output doesn’t match your needs

Remove context when:

  • It’s not relevant to the current question
  • You’re changing topics
  • You’ve established a pattern the AI follows

The Context Checklist

Before sending a prompt:

  • Did I explain what I’m working on?
  • Did I include relevant code/data?
  • Did I share error messages exactly?
  • Did I mention constraints?
  • Did I provide examples of what I want?
  • Did I show what I don’t want (if relevant)?

Context transforms AI from generic to useful.

Practice contextual prompting in Calliope →

Related Articles