Prompting Techniques
Context Sandwich

The Context Sandwich

The most important prompting technique. Give AI the full picture.

The Formula

[What exists] + [What you want] + [Constraints]

Examples

❌ Bad Prompt

"Add authentication"

AI doesn't know your tech stack, existing patterns, or constraints.

✅ Good Prompt

"We have a Next.js app with Prisma. Add email/password auth using 
NextAuth.js. Use the existing User model in schema.prisma. Follow 
the existing patterns in /app/api for route handlers. No OAuth 
for now, just credentials."

Breaking It Down

PartPurposeExample
What existsContext"We have a Next.js app with Prisma..."
What you wantGoal"Add email/password auth using NextAuth.js..."
ConstraintsBoundaries"No OAuth for now, just credentials."

More Examples

API Route

[What exists]
"We have a REST API using Express with PostgreSQL. 
Authentication is handled via JWT in the Authorization header."

[What you want]
"Create a new endpoint GET /api/users/:id that returns user 
profile data including their posts."

[Constraints]
"Return 404 if user not found. Only return public fields 
(no password hash). Include pagination for posts (max 10)."

React Component

[What exists]
"We're using React 18 with TypeScript and Tailwind. 
Look at /components/Card.tsx for our styling patterns."

[What you want]
"Create a UserProfile component that displays avatar, name, 
bio, and a list of recent posts."

[Constraints]
"Use the existing Card component for layout. Make it responsive. 
No external dependencies."

Pro Tip: The more specific your context, the better AI's output. Reference actual files when possible: "Follow the pattern in /src/services/UserService.ts"