AI2025년 12월 22일2분 읽기

LLM 구조화된 출력 — JSON Mode와 Schema 제약

YS
YoungSam
조회 191

구조화된 출력의 필요성

LLM 출력을 프로그래밍적으로 처리하려면 JSON 등 구조화된 형태가 필요합니다.

Claude Tool Use로 구조화

const response = await anthropic.messages.create({
  model: "claude-sonnet-4-20250514",
  tools: [{
    name: "extract_info",
    input_schema: {
      type: "object",
      properties: {
        name: { type: "string" },
        sentiment: { type: "string", enum: ["positive", "negative", "neutral"] },
        score: { type: "number", minimum: 0, maximum: 1 },
      },
      required: ["name", "sentiment", "score"],
    },
  }],
  tool_choice: { type: "tool", name: "extract_info" },
  messages: [{ role: "user", content: reviewText }],
});
LLMStructured OutputJSON

댓글 0

아직 댓글이 없습니다.