DevInterviewMasterStart free →
AI & AutomationFree to read

Prompt Basics

The Art of Talking to AI Effectively

Learn the foundational principles of prompt design - how to write clear, effective prompts that get great results from any LLM. From basic structure to common patterns, master the skill that makes the difference between mediocre and excellent AI output.

What is Prompt Engineering?

The Skill of Communicating Clearly with AI

Prompt Engineering Explained:

Prompt engineering is the practice of crafting inputs (prompts) to get the best possible outputs from Large Language Models. It is not magic or hacking - it is the art of clear, structured communication. Just like writing a good brief for a designer or giving clear instructions to a new team member.

The quality of your output is directly proportional to the quality of your input. A vague prompt gives vague results. A precise, well-structured prompt gives precise, useful results. This is true for every LLM - GPT, Claude, Gemini, Llama - they all respond better to better prompts.

Real-World Analogy - Ordering Food:

At a restaurant: "Give me something good" - the chef has no idea what you want. You might get anything. "I want a paneer tikka, medium spice, with extra mint chutney, no onions" - now the chef knows exactly what to make. Prompting an LLM works the same way. Be specific, give context, state your preferences.

Why It Matters:

  • Same model, different results: Two people using the same LLM can get wildly different quality outputs based solely on how they prompt
  • Cost efficiency: Better prompts need fewer iterations, saving tokens and money
  • Reliability: Well-designed prompts give consistent results, not random ones
  • Essential skill: As AI becomes central to workflows, prompt design is as important as Google search skills were 15 years ago

Note: Prompt engineering is not about tricks or hacks. It is about clear communication. If you can explain something clearly to a smart colleague, you can write a good prompt.

The Anatomy of a Good Prompt

Five Elements That Make Prompts Effective

1. Role / Context:

Tell the AI WHO it is and WHAT context it is operating in. This sets the frame for everything that follows.

Bad:  "Explain databases"
Good: "You are a senior backend engineer teaching a
       junior developer. Explain databases in simple
       terms with practical examples."

2. Clear Task / Instruction:

Be specific about WHAT you want. Do not leave it to interpretation.

Bad:  "Write about React"
Good: "Write a 300-word explanation of React hooks,
       covering useState and useEffect, with one
       practical example for each."

3. Input Data / Context:

Provide the information the AI needs to work with. The more relevant context, the better the output.

4. Output Format:

Specify HOW you want the result. Bullet points? JSON? Table? Paragraph? This eliminates guessing.

"Return the result as a JSON object with keys:
 - summary (string, max 100 words)
 - key_points (array of 3-5 strings)
 - difficulty (beginner/intermediate/advanced)"

5. Constraints / Boundaries:

Tell the AI what NOT to do, length limits, tone requirements, and any rules to follow.

"Keep the response under 200 words.
 Do not use technical jargon.
 Do not make up information - say 'I do not know' if unsure.
 Respond in a friendly, conversational tone."

Note: Not every prompt needs all five elements. Simple tasks need simple prompts. But for complex tasks, including all five dramatically improves output quality.

Common Prompt Patterns for Better Results

Proven Patterns That Work Across All LLMs

Pattern 1: Step-by-Step Instructions

Break complex tasks into numbered steps. The AI follows them sequentially, producing more organized output.

"Analyze this code review:
 1. First, identify any bugs or errors
 2. Then, suggest performance improvements
 3. Finally, rate the code quality 1-10 with justification"

Pattern 2: Example-Based (Few-Shot)

Show the AI examples of what you want. This is incredibly powerful for establishing patterns.

"Convert company names to ticker symbols:
 Apple Inc -> AAPL
 Microsoft Corporation -> MSFT
 Tesla Inc -> TSLA
 Reliance Industries -> ?"

AI: "RELIANCE"

Pattern 3: Persona Assignment

Give the AI a specific role to adopt. This shapes the vocabulary, depth, and style of the response.

"You are a security auditor reviewing a web application.
 Examine this code for vulnerabilities."

vs

"You are a product manager explaining to stakeholders.
 Explain why this code change improves user experience."

Pattern 4: Structured Output Request

Ask for output in a specific structure. Tables, JSON, bullet points, numbered lists - the AI follows the structure faithfully.

Pattern 5: Negative Constraints

Tell the AI what to AVOID. This is often more effective than only saying what you want.

"Explain microservices to a junior developer.
 - Do NOT use the word 'distributed'
 - Do NOT assume they know Docker
 - Do NOT write code, use analogies instead"

Note: These patterns work with every LLM. Learn them once, use them everywhere. Start with step-by-step instructions and examples - they give the biggest improvement.

Common Prompt Mistakes to Avoid

Pitfalls That Lead to Poor AI Output

Mistake 1: Being Too Vague

"Write something about JavaScript" will give you a generic, surface-level response. The AI does not know your audience, purpose, or desired depth. Be specific: WHO is the audience? WHAT aspect? HOW detailed?

Mistake 2: Overloading a Single Prompt

Trying to do 10 things in one prompt leads to mediocre results on all of them. Break complex tasks into smaller, focused prompts. Chain the outputs if needed.

Mistake 3: Not Specifying Format

If you want a bullet list and get a paragraph, it is your fault for not asking. Always specify the output format: "Respond as bullet points", "Return as JSON", "Write as a table with columns X, Y, Z".

Mistake 4: Assuming Context the AI Does Not Have

The AI does not know about your project, your codebase, or yesterday's conversation (unless you provide it). Always include relevant context in the prompt. Do not assume the AI can read your mind.

Mistake 5: Not Iterating

Your first prompt is rarely perfect. Treat prompt design as iterative. Write a prompt, check the output, refine the prompt, check again. Each iteration improves the result. Save your best prompts for reuse.

Note: The biggest prompt mistake is being lazy with instructions. Spend an extra 30 seconds making your prompt specific and you will save minutes fixing bad output.

Before & After - Real Prompt Transformations

See the Difference Good Prompts Make

Before (Weak Prompt):

"Explain REST APIs"

Result: Generic 3-paragraph explanation you can find on any blog. Not tailored, not actionable, not memorable.

After (Strong Prompt):

"You are a senior backend developer mentoring a junior who just learned HTTP basics. Explain REST APIs using a food delivery app (like Swiggy) as the example. Cover: what REST is, the 4 main HTTP methods with Swiggy examples, and 3 best practices. Keep it under 400 words. Use simple language, no jargon. End with a practice exercise."

Result: Engaging, practical explanation with Swiggy examples, exactly 4 methods covered, 3 clear best practices, and a practice exercise. Immediately useful.

Another Example - Code Review:

Weak: "Review this code"

Strong: "Review this Node.js Express middleware for: 1) Security vulnerabilities (especially injection and auth bypass) 2) Performance issues (N+1 queries, memory leaks) 3) Error handling gaps. For each issue found, explain the risk and suggest a fix. Rate severity as Critical/High/Medium/Low."

The Prompt Improvement Checklist:

  • Did I specify the role/persona?
  • Is the task crystal clear?
  • Did I provide enough context?
  • Did I specify the output format?
  • Did I set constraints (length, tone, what to avoid)?
  • Would a smart but literal person understand exactly what I want?

Note: Save your best prompts as templates. Over time, you will build a personal library of proven prompts for common tasks.

Interview Questions

Q: What is prompt engineering and why is it important?

Prompt engineering is the practice of crafting effective inputs to get the best outputs from LLMs. It matters because the same model gives wildly different quality results based on the prompt. Better prompts lead to more accurate, consistent, and useful AI outputs. It is fundamentally about clear, structured communication - telling the AI exactly what you need with enough context and constraints.

Q: What are the key elements of a well-structured prompt?

Five elements: (1) Role/Context - who the AI should be and what situation it is in. (2) Clear Task - specific instruction of what to do. (3) Input Data - relevant information the AI needs. (4) Output Format - how the result should be structured (JSON, bullets, table). (5) Constraints - length limits, tone, what to avoid. Not every prompt needs all five, but complex tasks benefit from including them all.

Q: What are common prompt design mistakes?

Common mistakes: (1) Being too vague - "write about X" without specifying audience, depth, or purpose. (2) Overloading - trying to do too many things in one prompt. (3) Not specifying format - getting paragraphs when you wanted bullets. (4) Assuming context - expecting the AI to know about your project. (5) Not iterating - treating the first prompt as final instead of refining based on output.

Q: How does providing examples in a prompt improve results?

Examples (few-shot prompting) demonstrate the exact pattern you want the AI to follow. Instead of explaining the format in words, you show it. The AI pattern-matches from examples and produces output following the same structure, tone, and style. This is especially powerful for format-sensitive tasks (data transformation, classification, style matching).

Q: What is the role of negative constraints in prompts?

Negative constraints tell the AI what to avoid. Examples: "Do not use jargon", "Do not include code", "Do not assume prior knowledge". They are often more effective than positive instructions because they prevent specific failure modes. The AI tends to follow prohibitions strictly. Combine positive instructions (what to do) with negative constraints (what to avoid) for the best results.

Frequently Asked Questions

What is Prompt Basics?

Learn the foundational principles of prompt design - how to write clear, effective prompts that get great results from any LLM. From basic structure to common patterns, master the skill that makes the difference between mediocre and excellent AI output.

How does Prompt Basics work?

The Skill of Communicating Clearly with AI Prompt Engineering Explained: Prompt engineering is the practice of crafting inputs (prompts) to get the best possible outputs from Large Language Models. It is not magic or hacking - it is the art of clear, structured communication.

Browse all AI & Automation topics →

Practice this on DevInterviewMaster

Read the full Prompt Basics breakdown with interactive demos, quizzes, and Hinglish notes.

Open the interactive topic →

800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.