Skip to content
DocsUse AIfundamentalsPrompting Fundamentals
Chapter 4 of 15·fundamentals·8 min read

Prompting Fundamentals

Cơ Bản Về Prompt

How to write effective prompts for AI coding assistants

Hover or tap any paragraph to see Vietnamese translation

The Art of Prompting

A prompt is how you communicate with AI. A good prompt helps Claude understand exactly what you need, while vague prompts lead to unexpected results.

Prompting skill is not about learning 'magic words' - it's about communicating clearly, providing appropriate context, and setting correct expectations.

Fundamental Principles

Effective Prompting Flow
1
Define Goal
What do you need?
2
Add Context
Why and where?
3
Set Constraints
Requirements
4
Review Output
Check result

1. Be Specific and Clear

Instead of generic requests, describe exactly what you want. Include details about input, output, and constraints.

Specificity Examples
1# Bad - Too vague2"fix the bug"34# Good - Specific5"fix the login bug where users get 401 error after password reset"67# Bad - No context8"add validation"910# Good - With context11"add email validation to the signup form -12check format and show error below the input field"

2. Provide Context

Claude works better when it understands the big picture. Explain why you need this and where it fits in the system.

Context Examples
1# Without context2"create a user model"34# With context5"create a user model for our e-commerce app.6Users can have multiple addresses, a shopping cart,7and order history. We use PostgreSQL with Prisma."

3. Break Down Large Tasks

Instead of requesting a complex feature in one prompt, break it into smaller steps. This helps Claude focus and lets you review each part.

Task Breakdown
1# One big request (risky)2"build a complete authentication system with3login, signup, password reset, and OAuth"45# Step by step (better)61. "create the user database schema for auth"72. "add signup endpoint with email validation"83. "add login endpoint with JWT tokens"94. "add password reset flow with email"105. "add Google OAuth integration"

Effective Patterns

Pattern: Explain First

Asking Claude to explain before acting helps confirm it understands the problem correctly.

Explain First Pattern
1"explain how the current caching system works,2then suggest improvements for handling cache invalidation"34"analyze the performance bottleneck in the search function,5then propose a solution"

Pattern: Show Examples

Providing examples of desired input/output helps Claude understand exactly the format and style you need.

Example Pattern
1"convert this data to the following format:23Input:4{ name: 'John', age: 30 }56Expected output:7<user>8  <name>John</name>9  <age>30</age>10</user>1112Now convert this: { name: 'Jane', age: 25, role: 'admin' }"

Pattern: Constraints

Setting clear constraints helps Claude produce code that fits your technical requirements.

Constraints Pattern
1"create a rate limiter with these constraints:2- max 100 requests per minute per user3- use Redis for storage4- return 429 status when limit exceeded5- include retry-after header6- must be middleware compatible with Express"

Common Mistakes

1. Too Vague

Vague vs Specific
1# Avoid2"make it better"3"fix the errors"4"improve performance"56# Instead7"reduce the API response time from 2s to under 500ms"8"fix the TypeScript errors in UserService.ts"9"add index to speed up user lookup by email"

2. Too Much at Once

One at a Time
1# Avoid - overwhelming2"refactor the entire codebase to use TypeScript,3add tests, improve error handling, and optimize for performance"45# Instead - one thing at a time6"convert utils/helpers.js to TypeScript"7# then after completion:8"add unit tests for utils/helpers.ts"

3. Missing Context

Missing Context
1# Missing context2"why isn't this working?"34# With context5"this function should return filtered users but returns empty array.6Here's the input data: [...]7Here's the function: [...]8What's wrong?"

Advanced Prompting

Chain of Thought

Asking Claude to think step by step helps with complex problems requiring logical analysis.

Chain of Thought
1"analyze this algorithm step by step:21. identify the time complexity of each loop32. find any redundant operations43. suggest optimizations54. show the improved version with explanations"

Role Prompting

Putting Claude in a specific role can help it approach problems from the right perspective.

Role Prompting
1"as a security expert, review this authentication code2and identify potential vulnerabilities"34"as a senior React developer, review this component5for best practices and performance issues"
Tip
Prompting is a skill - you'll get better over time. Don't hesitate to experiment and learn from what works.

Key Takeaways

Điểm Chính

  • Be specific - include details about input, output, and constraintsCụ thể - bao gồm chi tiết về input, output và ràng buộc
  • Provide context - explain why and where it fits in the systemCung cấp context - giải thích tại sao và nó nằm ở đâu trong hệ thống
  • Break down large tasks into smaller, reviewable stepsChia nhỏ tác vụ lớn thành các bước nhỏ hơn, có thể review
  • Show examples when you need specific formatsĐưa ví dụ khi bạn cần format cụ thể

Practice

Test your understanding of this chapter

Quiz

Which prompt is more effective?

Prompt nào hiệu quả hơn?

True or False

You should always ask for an entire feature in one prompt to save time.

Bạn nên luôn yêu cầu toàn bộ tính năng trong một prompt để tiết kiệm thời gian.

Code Challenge

Complete the prompting pattern name for providing sample input/output

Hoàn thành tên pattern prompting cho việc cung cấp input/output mẫu

Show 
Quiz

What is 'Chain of Thought' prompting?

'Chain of Thought' prompting là gì?

← → to navigate chapters
Built: 4/8/2026, 12:01:11 PM