← 노드 한 장 전체#41 · Structured Output Parser

Structured Output Parser

주문 문장 세 개를 같은 JSON 칸으로

이 글은 이런 분께AI의 답을 정해진 JSON 필드와 자료형으로 받아 다음 노드에 넘기고 싶은 분
Structured Output Parser 영상 표지

1분 영상은 @workflow.hanjang 에 순서대로 공개돼요

JSON 받기

주문·문의 문장 3개, 같은 JSON 칸으로.

노드 한 장 #41 · Structured Output Parser

먼저 결과부터

직접 작성한 주문·문의 샘플 3건을 Structured Output Parser의 고정 JSON Schema로 product(문자열), quantity(숫자), topic(order/shipping/refund)에 맞춰 받았어요. 이번 실행은 형태 검사와 원문별 사전 정답 비교 모두 3/3 통과했습니다. 형태가 맞아도 내용의 사실성은 별도 확인이 필요하고, 항상 성공·정확함을 보장하지 않습니다. 파서에는 고정 스키마를 넣고, 원문 표현식은 부모 Chain에서 항목별로 처리했어요. 실제 실행 #74813(2026.10.30 02:04 KST), 직접 작성한 샘플이며 실제 고객 데이터가 아닙니다.
우리가 실제로 돌린 기록 · 실행 #74813 · 2026-10-30
Structured Output Parser 실제 n8n 화면 1
우리가 실제로 돌린 n8n 화면 (실행 #74813, 2026-10-30)
Structured Output Parser 실제 n8n 화면 2
우리가 실제로 돌린 n8n 화면 (실행 #74813, 2026-10-30)

따라 하기

아래 설정값은 이 영상에 나온 워크플로우 JSON에서 그대로 가져왔어요. n8n 캔버스에서 +를 눌러 노드를 순서대로 추가하고 같은 값을 넣으면 돼요. 빨간 제목이 이번 편의 주인공 노드예요. 표 왼쪽은 n8n 편집기에 보이는 칸 이름, 오른쪽은 실제로 넣은 값이에요. 직접 입력하기 번거로우면 JSON을 받아 ⋯ → Import from File로 가져오세요.

Step 1. Manual Trigger 노드 추가이름: Run manually

설정 없이 그대로 추가해요.

Step 2. Code 노드 추가이름: Sample inquiries

JavaScript
// 직접 작성한 실습 샘플. 실제 주문/고객 데이터 아님.
return [{"text":"샘플 주문이에요. 파란 머그컵 두 개를 주문하고 싶어요.","expected":{"product":"파란 머그컵","quantity":2,"topic":"order"}},{"text":"샘플 배송 문의: 접이식 우산 3개, 언제 출발하나요?","expected":{"product":"접이식 우산","quantity":3,"topic":"shipping"}},{"text":"샘플 환불 문의입니다. 노트 한 권을 환불하고 싶어요.","expected":{"product":"노트","quantity":1,"topic":"refund"}}].map((x,i)=>({json:{sample:true,no:i+1,...x}}));

Step 3. Basic LLM Chain 노드 추가이름: Basic LLM Chain

Source for Prompt (User Message)Define below
Require Specific Output Format켜짐
Prompt (User Message)
다음은 직접 작성한 샘플 주문/문의입니다. product는 원문의 상품명 그대로(수량/조사는 제외), quantity는 개수 숫자, topic은 order(주문), shipping(배송), refund(환불) 중 하나로 추출하세요. 원문에 없는 내용은 만들지 마세요.
원문: {{ $json.text }}
Batch Processing › Batch Size1

Step 4. OpenAI Chat Model 노드 추가이름: OpenAI Chat Model

Modelgpt-4.1-mini
Options › Sampling Temperature0

Step 5. Structured Output Parser 노드 추가이름: Structured Output Parser

Schema TypeDefine using JSON Schema
Input Schema
{
  "type": "object",
  "properties": {
    "product": {
      "type": "string"
    },
    "quantity": {
      "type": "number"
    },
    "topic": {
      "type": "string",
      "enum": [
        "order",
        "shipping",
…
Auto-Fix Format꺼짐

Step 6. Code 노드 추가이름: Verify shape and sample facts separately

JavaScript
const src=$('Sample inquiries').all(); const input=$input.all(); if(input.length!==3)throw Error('Expected 3 actual outputs'); return input.map((it,i)=>{const s=src[it.pairedItem?.item??i].json; const o=it.json.text??it.json.output??it.json; const shape=typeof o.product==='string'&&typeof o.quantity==='number'&&['order','shipping','refund'].includes(o.topic)&&Object.keys(o).sort().join(',')==='product,quantity,topic'; const match=o.product===s.expected.product&&o.quantity===s.expected.quantity&&o.topic===s.expected.topic; return {json:{sample:true,no:s.no,sourceText:s.text,result:o,schemaValid:shape,sampleFactMatch:match},pairedItem:{item:i}};});

가져와서 쓸 때 확인할 것

노드의 모든 옵션은 n8n 공식 문서에서 볼 수 있어요.