C.W.K.
Stream
Lesson 02 of 05 · published

JSON Schema 가 Contract

~26 min · json-schema, parameters, description, required

Level 0호기심 많은 독자
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Tool 정의는 너와 모델 사이의 contract 야. 그 contract 에서 가장 평가절하된 필드는 description — 이 tool 을 언제 왜 쓰는지 모델한테 말해주는 prose. 프로덕션 팀이 description 에는 투자 부족, 화려한 schema 에는 과투자 — 흔한 실수야. 모델은 description 을 읽어서 tool 을 고르지, 네 희망사항 읽어서 안 골라.

Schema 면에서, 모든 modern provider 는 JSON Schema 를 — 작은 사투리 차이로 — 말해. 항상 통하는 모양은: {"type": "object", "properties": {…}, "required": [...]} 에 각 property 가 자기 type 과 한 줄 description 을 들고 있는 거. 닫힌 집합엔 enum ("status": open|closed|in_progress 중 하나). 날짜와 이메일 같은 건 format — 대부분 provider 가 강제하진 않지만, 모델이 valid 한 출력 내도록 bias 줘.

Description 의 세 가지 룰, 어렵게 배운 거:

  • Tool description: '뭐 하는지' 가 아니라 '언제 쓰는지'. "Get current weather for a city" 는 정의. "Use this when the user asks about today's weather, temperature, or whether it will rain in a named city" 는 contract.
  • 파라미터 description: format 과 edge case. "city name" 만 말고 — "city name in English; for cities with translations like 'Seoul' use the romanized form, not '서울'." 그게 가장 흔한 실패 모드를 막는 description.
  • Required 는 진짜 required. 파라미터가 정답 위해 필수면, required 마크. Optional 은 절반은 빠져 — 모델이 안 물어. Required 는 빠지면 구조화된 재질문 발동.

Schema 디자인은 engineering 으로 위장한 글쓰기 문제야. Schema 가 맞다는 건, 네 codebase 처음 본 동료가 tool 정의 읽고 90% 정확도로 — 이 tool 이 뭘 하고 모델이 언제 고를지 — 예측할 수 있을 때야.

Code

잘 description 된 tool — Anthropic 모양·python
{
  "name": "search_orders",
  "description": (
    "Search the customer's order history. Use this when the user mentions "
    "an order, a tracking number, a refund, or asks 'where is my package'. "
    "Do NOT use this for product browsing — use search_catalog for that."
  ),
  "input_schema": {
    "type": "object",
    "properties": {
      "customer_id": {
        "type": "string",
        "description": "The customer's account ID, exactly as it appears in the user's profile context."
      },
      "status": {
        "type": "string",
        "enum": ["pending", "shipped", "delivered", "returned"],
        "description": "Filter by status. Omit to search all statuses."
      },
      "since": {
        "type": "string",
        "format": "date",
        "description": "Earliest order date to consider, in YYYY-MM-DD format."
      }
    },
    "required": ["customer_id"]
  }
}
OpenAI Responses API — 같은 모양, 약간 다른 envelope·python
tools = [{
    "type": "function",
    "name": "search_orders",
    "description": "...",
    "parameters": {
        "type": "object",
        "properties": { ... },
        "required": ["customer_id"]
    }
}]

External links

Exercise

이미 코드에 쓰는 tool 하나 골라서 description 을 세 번 다시 써: '뭐 하는지', '언제 쓰는지', '언제 쓰지 말아야 하는지 (대신 뭘 쓸지)'. 같은 prompt 로 모델한테 세 버전 다 돌리고 선택 정확도 봐. '언제 쓰는지' 가 보통 이기고, '언제 쓰지 말아야 하는지' 는 겹치는 tool 들 사이의 tiebreaker.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.