[Tech Blog] JSON으로 말하는 AI 에이전트: '설명 가능한 번역'을 위한 백엔드 아키텍처
[Tech Blog] JSON으로 말하는 AI 에이전트: '설명 가능한 번역'을 위한 백엔드 아키텍처
작성일: 2026-01-07
작성자: 박용락 PM ((주)뷰티인사이드랩 AI솔루션팀)
1. 들어가며: "왜 이렇게 번역했나요?"에 대답하기
어제 우리는 단순 번역을 넘어 '문맥(Context)'을 이해하는 에이전트를 만들었습니다. 하지만 마케팅 팀에서 새로운 피드백이 왔습니다.
"결과물은 좋은데, AI가 왜 이 단어를 선택했는지 이유를 알 수 있을까요? 클라이언트 설득을 위해 근거가 필요합니다."
단순히 Target Text만 던져주는 것으로는 부족했습니다. 우리는 "설명 가능한 AI (Explainable AI)" 레벨로 에이전트를 고도화해야 했습니다. 오늘 우리는 FastAPI와 Pydantic을 활용해, AI가 자신의 전략을 구조화된 JSON으로 설명하게 만드는 과정을 공유합니다.
2. Architecture: Strings to Objects
기존의 LLM 애플리케이션은 대부분 String 입출력에 의존합니다. 하지만 엔터프라이즈 환경에서는 Structure가 생명입니다.
2.1. Pydantic으로 응답 규격화 (schemas.py)
우리는 AI의 출력을 다음과 같이 정의했습니다.
class LocalizationResponse(BaseModel):
target_text: str = Field(..., description="The transcreated marketing copy")
headline: str = Field(..., description="A catchy, market-fit headline")
strategy_points: List[str] = Field(..., description="3 Reasons WHY this copy works")
summary: str = Field(..., description="Brief transformation summary")이제 AI는 마음대로 말할 수 없습니다. 반드시 헤드라인, 본문, 그리고 3가지 전략 포인트를 채워야만 통과시킵니다.
3. Implementation: Think-Strategy-Act 패턴
3.1. JSON Mode의 활용 (utils.py)
OpenAI의 json_mode는 강력하지만, 그것만으로는 부족합니다. 프롬프트 내에서 명확한 스키마를 제시해야 합니다.
prompt = """
[Instruction]
Do not just translate. Analyze the K-Beauty Strategy and output JSON.
OUTPUT FORMAT (JSON ONLY):
{
"headline": "...",
"target_text": "...",
"strategy_points": [
"Replaced 'Mugwort' with 'Artemisia' for premium positioning",
"Used 'Clinically Proven' to align with Verification trend"
]
}
"""이제 에이전트는 번역을 수행하면서 동시에 자신의 사고 과정(Chain of Thought)을 strategy_points에 기록합니다.
4. Troubleshooting: Validation Hell 탈출기
프론트엔드(Next.js)와 백엔드(FastAPI)를 연동하는 과정에서 422 Unprocessable Entity 에러는 피할 수 없는 통과의례입니다.
4.1. The Camel vs. Snake War
- Frontend:
categoryId(Camel Case) - Backend:
category_idorcategory(Snake Case)
이 불일치를 해결하기 위해 우리는 Pydantic의 Field(alias=...)를 적극 활용했습니다.
class TranslationRequest(BaseModel):
source_text: str = Field(..., alias="sourceText")
category: str = Field("general", alias="categoryId") 이 한 줄의 코드로, 프론트엔드 개발자는 JavaScript 관습(Camel)을 유지하고, 백엔드 개발자는 Python 관습(Snake)을 유지할 수 있게 되었습니다. **"Convention over Configuration"**의 승리입니다.
5. 결과: 신뢰할 수 있는 파트너 AI
이제 마케터는 화면에서 다음을 봅니다.
Original: "쑥 성분이 들어있어 순하다"
Transcreated: "Formulated with Artemisia..."
Why?:
- 'Mugwort' is banned due to weed connotation.
- 'Gentle' is too vague; upgraded to 'Hypoallergenic'.
이것이 바로 우리가 추구하는 **"Human-AI Collaborative Workflow"**의 핵심입니다. AI는 단순한 도구가 아니라, 논리적인 근거를 가진 파트너가 되어야 합니다.
Next Step: 이 구조화된 데이터를 기반으로 대량의 상품 정보를 자동 변환하는 Bulk Pipeline 구축으로 이어집니다.
Beauty Insight Editor
Sharing insights on K-Beauty trends and data-driven export strategies. We help brands expand globally with the power of AI.