ai-startup
CHAPTER 29 / 100
읽기 약 2분
FUNCTION
프롬프트 엔지니어링: 서비스용 프롬프트 설계
핵심 개념
system prompt·few-shot·구조화·재사용 — 일관된 AI 응답.
본문
프롬프트 4 요소
1. Role (역할)
"You are a [전문가] who [전문성]"
2. Task (작업)
"Your task is to [구체적 목표]"
3. Constraints (제약)
"Always follow these rules:
- [규칙 1]
- [규칙 2]"
4. Output Format (출력)
"Respond in this format:
[형식 예시]"실전 예시 — 영어 첨삭
const SYSTEM_PROMPT = `You are an English grammar tutor for Korean professionals.
Your task: Analyze the user's English text and provide:
1. Corrections with explanations in Korean
2. More natural alternatives
3. Common mistake pattern (if applicable)
Constraints:
- Tone: Encouraging, not condescending
- Length: Concise (max 300 words)
- Always explain WHY in Korean
- Suggest 2-3 alternative phrasings
Output format:
## 원문
[user input]
## 수정사항
[bullet list with Korean explanation]
## 자연스러운 대안
1. [alternative 1]
2. [alternative 2]
## 같은 실수 패턴
[if applicable]`;Few-Shot Learning
const messages = [
{ role: 'system', content: SYSTEM_PROMPT },
// 예시 1
{ role: 'user', content: 'I want to discuss about the project.' },
{ role: 'assistant', content: `## 수정사항
- "discuss about" → "discuss" (discuss는 자동사)
## 자연스러운 대안
1. I want to discuss the project.
2. I'd like to talk about the project.` },
// 예시 2
{ role: 'user', content: 'I am agree with you.' },
{ role: 'assistant', content: `## 수정사항
- "I am agree" → "I agree" (agree는 동사, be 동사 불필요)` },
// 실제
{ role: 'user', content: userInput },
];구조화 출력 (JSON Schema)
import { generateObject } from 'ai';
import { z } from 'zod';
const ResultSchema = z.object({
correction: z.string(),
explanation: z.string().describe('Korean explanation'),
alternatives: z.array(z.string()).min(2).max(3),
pattern: z.string().optional(),
confidence: z.number().min(0).max(1),
});
const { object } = await generateObject({
model: anthropic('claude-sonnet-4-6'),
schema: ResultSchema,
prompt: `Analyze this English: "${userInput}"`,
});
// object.correction, object.alternatives 등 타입 안전프롬프트 변수 관리
// lib/prompts.ts
export const PROMPTS = {
englishTutor: {
system: `You are an English tutor...`,
examples: [...],
version: '1.2.0',
},
contentWriter: {
system: `You are a content writer...`,
version: '2.0.0',
},
};
// 사용
const result = streamText({
system: PROMPTS.englishTutor.system,
messages,
});
// 버전 업데이트 시 — 명시적
// A/B 테스트 가능주의사항
1. 너무 긴 시스템 프롬프트 → 비용·성능 저하
→ 핵심만 (300 토큰 이내)
2. 한국어 + 영어 혼용 일관성
→ 명확히 명시
3. Hallucination 방지
→ "If uncertain, say 'I don't know'"
→ "Only use information from the provided context"
4. Jailbreak 방어
→ 시스템 프롬프트로 제한
→ 사용자 입력 검증프롬프트 캐싱 (Anthropic)
// 같은 시스템 프롬프트 반복 → 캐시
const result = streamText({
model: anthropic('claude-sonnet-4-6'),
messages: [
{
role: 'system',
content: LONG_SYSTEM_PROMPT,
// ↓ 캐시 활성화
providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } },
},
...messages,
],
});
// 효과:
// - 비용 90% 감소 (캐시 히트)
// - 응답 시간 50% 단축다음 챕터
CH.30 "RAG 구현: 문서 업로드 → AI 검색".
AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
무료
월 $0 — 검증·시작 단계
프롬프트 엔지니어링을 무료 도구만으로 시작하는 방법을 알려줘.
소자본
월 $20~50 — MVP·초기 운영
월 $20~50 예산으로 프롬프트 엔지니어링을 검증·MVP 단계까지 진행하는 전략은?
프로덕션
월 $200~500 — 성장 단계
프롬프트 엔지니어링을 프로덕션 단계로 확장할 때 필요한 도구·운영 체계는?
스택
풀스택 — 도구 조합 분석
2026년 프롬프트 엔지니어링 관련 도구 5개를 조합한 추천 스택을 알려줘.
⭐ 이것만 기억하세요
프롬프트 엔지니어링: 서비스용 프롬프트 설계는 이 3가지만 확실히 잡으세요
1.4 요소 (Role·Task·Constraints·Format) = 일관된 AI 응답
2.Few-Shot으로 출력 형식 학습 → 정확도 30% 향상
3.프롬프트 캐싱 (Anthropic) = 비용 90% 절감
공유하기
진행도 29 / 100