๐จ ํ๋กฌํํธ ์์ง๋์ด๋ง (Dev Prompt Engineering)
์ด ์ํฌํ๋ก์ฐ๋ anthropics/prompt-eng-interactive-tutorial์ ์์น์ ์ฌ์ฉํ์ฌ ์ต์ ์ Claude ํ๋กฌํํธ๋ฅผ ์์ฑํฉ๋๋ค.
1. ์ด๊ธฐํ (Initialization)
- ์คํฌ ๋ก๋:
this document๋ฅผ ์ฝ์ด "Anthropic Best Practices"๋ฅผ ํ์ ํฉ๋๋ค. - ๋ชฉํ ์ค์ : ์ฌ์ฉ์์๊ฒ ๋ค์ ์ธ ๊ฐ์ง๋ฅผ ๋ฌป์ต๋๋ค.
- Role: ์์ด์ ํธ๊ฐ ์ด๋ค ํ๋ฅด์๋๋ฅผ ๊ฐ์ ธ์ผ ํฉ๋๊น?
- Task: ์ํํด์ผ ํ ํต์ฌ ์์ ์ ๋ฌด์์ ๋๊น?
- Constraint: ์ถ๋ ฅ ํ์(JSON, XML ๋ฑ)์ด๋ ์ ์ฝ ์ฌํญ์ ๋ฌด์์ ๋๊น?
- Language Check: ๋ค์ ๊ท์น์ ์ฌ์ฉ์์๊ฒ ์ธ์ง์ํต๋๋ค.
- ํ๋กฌํํธ ๋ณธ๋ฌธ: ๋ชจ๋ธ ์ฑ๋ฅ ๊ทน๋ํ๋ฅผ ์ํด ์์ด๋ก ์์ฑ๋ฉ๋๋ค.
- ์ต์ข ๋ต๋ณ: ์ฌ์ฉ์๊ฐ ์ฝ๊ธฐ ํธํ๋๋ก ํ๊ตญ์ด๋ก ์ถ๋ ฅ๋๋๋ก ์ค์ ํฉ๋๋ค.
2. ์ด์ ์์ฑ (Drafting - Context & Role)
"Context First, Instructions Later"
- ํ
ํ๋ฆฟ ๋ก๋:
resources/prompt-template.md๋ฅผ ๋ก๋ํฉ๋๋ค. - ์ฌ๋กฏ ์ฑ์ฐ๊ธฐ (Slot Filling): ์ฌ์ฉ์ ์
๋ ฅ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ํ
ํ๋ฆฟ์
{{ }}ํ๋ ์ด์คํ๋๋ฅผ ์ฑ์๋๋ค.{{DOMAIN}}: Role ์ ๋ณด{{GOAL}}: Task ์ ๋ณด{{YEARS}}: (Optional) ๊ฒฝ๋ ฅ ์ฐ์ฐจ (๊ธฐ๋ณธ๊ฐ: Senior/10+)
- Draft V1 (Strict Adherence):
- ๊ตฌ์กฐ ์ ์ง:
prompt-template.md์ ๋ชจ๋ XML ํ๊ทธ(<system_role>,<context_and_data>๋ฑ)์ ๋ด์ฉ์ ๊ทธ๋๋ก ์ ์งํด์ผ ํฉ๋๋ค. - ์์
๋ด์ฉ: ์ค์ง
{{ }}๋ก ๊ฐ์ธ์ง ํ๋ ์ด์คํ๋๋ง ์ฌ์ฉ์์ ์ ๋ ฅ์ผ๋ก ๊ต์ฒดํฉ๋๋ค. ์์๋ก ์น์ ์ ์๋ตํ๊ฑฐ๋ ์์ฝํ์ง ๋ง์ญ์์ค. - ์์ฑ๋ ์ ์ฒด ํ๋กฌํํธ๋ฅผ ์ฌ์ฉ์์๊ฒ ์ ์ํฉ๋๋ค.
- ๊ตฌ์กฐ ์ ์ง:
3. ๊ณ ๋ํ (Refining - CoT & Few-Shot)
"์๊ฐํ๊ฒ ๋ง๋ค๊ณ , ์์๋ฅผ ๋ณด์ฌ์ฃผ์ธ์."
- ์์ ์ถ๊ฐ (Few-Shot): ์ฌ์ฉ์๊ฐ ์ํ๋ ์ด์์ ์ธ ์ ์ถ๋ ฅ ์์๋ฅผ 2~3๊ฐ ์ถ๊ฐํฉ๋๋ค.
- CoT ์ ์ฉ: ๋ณต์กํ ์์
์ธ ๊ฒฝ์ฐ,
<thinking>ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ๋จ๊ณ๋ณ๋ก ์ถ๋ก ํ๋๋ก ์ ๋ํฉ๋๋ค. ("Think step-by-step") - Draft V2: ๊ฐ์ ๋ ํ๋กฌํํธ๋ฅผ ์์ฑํฉ๋๋ค.
4. ๊ฒ์ฆ ๋ฐ ์ต์ ํ (Verification)
- ์๋ฎฌ๋ ์ด์ : ์์ฑ๋ ํ๋กฌํํธ๋ฅผ ์์ด์ ํธ ์ค์ค๋ก ํ๊ฐํด๋ด ๋๋ค. (Self-Correction)
- Edge Case ์ ๊ฒ: "๋ชจ๋ฅด๊ฒ ์ผ๋ฉด ๋ชจ๋ฅธ๋ค๊ณ ๋งํด" ๋ฑ์ ํ๊ฐ(Hallucination) ๋ฐฉ์ง ๋ฌธ๊ตฌ๊ฐ ์๋์ง ํ์ธํฉ๋๋ค.
- ์๋ฃ: ์ต์ข ํ๋กฌํํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
Standards & Rules
Prompt Engineering (Dev Prompt Engineering)
Core Principles (Anthropic Best Practices)
1. The "Context-First" Rule
- Context: Always provide relevant context before the instruction.
- Role: Assign a persona (e.g., "You are an expert Python architect").
- XML Tags: Use XML tags (e.g.,
<documents>,<instruction>) to structure input. Claude loves XML.
2. The Power of Examples (Few-Shot)
- Show, Don't Just Tell.
- Provide 3+ examples of "Input -> Ideal Output" to guide style and format.
- Anti-Hallucination: Include examples of how to say "I don't know" or handle edge cases.
3. Precognition (Chain of Thought)
- Let Claude Think: For complex tasks, ask Claude to "Think step-by-step" before answering.
- Thinking Tags: Use
<thinking>blocks to verify logic before generating the final<answer>.
4. Language Strategy (Performance vs Usability)
- Prompt Language: English. (LLMs reason better in English). All instructions, constraints, and system prompts must be in English.
- Output Language: Korean. The final response meant for the user must be in Korean.
- Rule: "Think in English, Speak in Korean."
๐๏ธ Structure of a Great Prompt
- Role & Goal: Who is Claude? What is the objective?
- Context/Data: Reference materials wrapped in XML.
- Rules & Constraints: Dos and Don'ts.
- Examples (Few-Shot): Golden samples.
- Instruction: The immediate task.
- Pre-computation: "Take a deep breath and think step by step..."
โ Quality Standards
- Clarity: Unambiguous instructions.
- Separation: Data and instructions are visually distinct (XML).
- Iterative: Every prompt should be tested and refined.
Checklist
- [ ] Persona: Is a specific role assigned?
- [ ] XML Structuring: Are data parts wrapped in tags?
- [ ] Examples: Are there at least 2-3 examples?
- [ ] CoT: Is identifying the reasoning process (Thinking) required?