{
  "licence": "https://creativecommons.org/licenses/by/4.0/",
  "credit": "Saulius Beconis, sbeconis.com",
  "page": "https://sbeconis.com/lab/structured-output/",
  "url": "https://sbeconis.com/lab/structured-output/structured-2026-10-08.json",
  "note": "Measurements and text are CC BY 4.0. Source data and quoted excerpts keep their own licences: see \"attribution\".",
  "lab": "LAB/008",
  "title": "Structured output reliability",
  "date": "2026-10-08",
  "method": {
    "dataset": "CORD-v2 validation + test, 200 receipts (CC BY 4.0); input text rebuilt from the dataset's word annotations (no OCR errors)",
    "task": "receipt text → JSON with LAB/002's schema; scoring and normalisation from LAB/002",
    "free": "the prompt asks for JSON only; output parsed as-is, then leniently (code fences, surrounding text)",
    "grammar": "same prompt; llama.cpp constrains decoding to the JSON schema (json_schema request field)",
    "prompt": "Below is the text of a shop receipt, one printed line per line. Extract it as JSON with exactly these keys:\n{\"items\": [{\"name\": string, \"quantity\": integer or null, \"price\": string}], \"subtotal\": string or null, \"tax\": string or null, \"service\": string or null, \"discount\": string or null, \"total\": string or null, \"cash\": string or null, \"change\": string or null}\nOne entry in \"items\" per purchased line; \"price\" is the line amount as printed. Copy amounts exactly as printed. Use null for anything not on the receipt. Return only the JSON.\n\nReceipt:\n{text}",
    "models": "llama.cpp b11461 (CUDA 13.4); greedy; Qwen3-8B/14B thinking off"
  },
  "environment": {
    "gpu": "RTX 4070 12 GB",
    "llama.cpp": "b11461 (CUDA 13.4)"
  },
  "tables": {
    "results": {
      "caption": "200 receipts as text → JSON, each model with free and grammar-constrained decoding.",
      "columns": [
        {
          "key": "schema_valid",
          "label": "Valid against schema",
          "suffix": "%",
          "decimals": 1
        },
        {
          "key": "parseable_json",
          "label": "Parseable JSON",
          "suffix": "%",
          "decimals": 1
        },
        {
          "key": "field_accuracy",
          "label": "Field accuracy",
          "suffix": "%",
          "decimals": 1
        },
        {
          "key": "item_f1",
          "label": "Line items F1",
          "suffix": "%",
          "decimals": 1
        },
        {
          "key": "fully_correct",
          "label": "Receipt fully correct",
          "suffix": "%",
          "decimals": 1
        },
        {
          "key": "latency_p50_s",
          "label": "Median time (s)",
          "suffix": "",
          "decimals": 2
        }
      ],
      "rows": [
        {
          "label": "Qwen3-4B Instruct-2507 Q4_K_M · free",
          "cells": {
            "schema_valid": 92.5,
            "parseable_json": 100,
            "field_accuracy": 87.6,
            "item_f1": 84.5,
            "fully_correct": 44.5,
            "latency_p50_s": 1.06
          },
          "highlight": false
        },
        {
          "label": "Qwen3-4B Instruct-2507 Q4_K_M · grammar",
          "cells": {
            "schema_valid": 100,
            "parseable_json": 100,
            "field_accuracy": 87.6,
            "item_f1": 84.5,
            "fully_correct": 45,
            "latency_p50_s": 1.06
          },
          "highlight": true
        },
        {
          "label": "Qwen3-8B Q4_K_M · free",
          "cells": {
            "schema_valid": 94,
            "parseable_json": 97.5,
            "field_accuracy": 87.2,
            "item_f1": 77.2,
            "fully_correct": 47,
            "latency_p50_s": 1.5
          },
          "highlight": false
        },
        {
          "label": "Qwen3-8B Q4_K_M · grammar",
          "cells": {
            "schema_valid": 100,
            "parseable_json": 100,
            "field_accuracy": 89.9,
            "item_f1": 77.5,
            "fully_correct": 47,
            "latency_p50_s": 1.49
          },
          "highlight": true
        },
        {
          "label": "Qwen3-14B Q4_K_M · free",
          "cells": {
            "schema_valid": 96,
            "parseable_json": 100,
            "field_accuracy": 92.3,
            "item_f1": 87.1,
            "fully_correct": 56.5,
            "latency_p50_s": 2.85
          },
          "highlight": false
        },
        {
          "label": "Qwen3-14B Q4_K_M · grammar",
          "cells": {
            "schema_valid": 100,
            "parseable_json": 100,
            "field_accuracy": 92.3,
            "item_f1": 87.1,
            "fully_correct": 56.5,
            "latency_p50_s": 2.85
          },
          "highlight": true
        },
        {
          "label": "Phi-4-mini Q4_K_M · free",
          "cells": {
            "schema_valid": 88.5,
            "parseable_json": 93,
            "field_accuracy": 77.7,
            "item_f1": 73.3,
            "fully_correct": 36,
            "latency_p50_s": 0.83
          },
          "highlight": false
        },
        {
          "label": "Phi-4-mini Q4_K_M · grammar",
          "cells": {
            "schema_valid": 100,
            "parseable_json": 100,
            "field_accuracy": 81.9,
            "item_f1": 77.6,
            "fully_correct": 37,
            "latency_p50_s": 0.84
          },
          "highlight": true
        }
      ],
      "note": "Valid against schema: exactly the required keys and value types"
    },
    "forced": {
      "caption": "Lines where free decoding said the price was missing (null), and what grammar-constrained decoding wrote there instead.",
      "columns": [
        {
          "key": "placeholder",
          "label": "Placeholder",
          "decimals": 0
        },
        {
          "key": "item name",
          "label": "Item name",
          "decimals": 0
        },
        {
          "key": "invented amount",
          "label": "Invented amount",
          "decimals": 0
        }
      ],
      "rows": [
        {
          "label": "Qwen3-4B Instruct-2507 Q4_K_M",
          "cells": {
            "placeholder": 15,
            "item name": 1,
            "invented amount": 4
          }
        },
        {
          "label": "Qwen3-8B Q4_K_M",
          "cells": {
            "placeholder": 3,
            "item name": 0,
            "invented amount": 0
          }
        },
        {
          "label": "Qwen3-14B Q4_K_M",
          "cells": {
            "placeholder": 22,
            "item name": 0,
            "invented amount": 0
          }
        },
        {
          "label": "Phi-4-mini Q4_K_M",
          "cells": {
            "placeholder": 1,
            "item name": 0,
            "invented amount": 0
          }
        }
      ],
      "note": "Placeholder: empty, \"0\" or the text \"null\". Counted only on receipts where both modes produced the same number of lines"
    }
  },
  "charts": {
    "schema": {
      "title": "Output valid against the schema",
      "meta": "Scale 0–100% · free vs grammar-constrained",
      "max": 100,
      "suffix": "%",
      "groups": [
        {
          "label": "Qwen3-4B Instruct-2507 Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 92.5
            },
            {
              "label": "grammar",
              "value": 100,
              "highlight": true
            }
          ]
        },
        {
          "label": "Qwen3-8B Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 94
            },
            {
              "label": "grammar",
              "value": 100,
              "highlight": true
            }
          ]
        },
        {
          "label": "Qwen3-14B Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 96
            },
            {
              "label": "grammar",
              "value": 100,
              "highlight": true
            }
          ]
        },
        {
          "label": "Phi-4-mini Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 88.5
            },
            {
              "label": "grammar",
              "value": 100,
              "highlight": true
            }
          ]
        }
      ]
    },
    "fields": {
      "title": "Field accuracy",
      "meta": "Scale 0–100% · same fields, same receipts",
      "max": 100,
      "suffix": "%",
      "groups": [
        {
          "label": "Qwen3-4B Instruct-2507 Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 87.6
            },
            {
              "label": "grammar",
              "value": 87.6,
              "highlight": true
            }
          ]
        },
        {
          "label": "Qwen3-8B Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 87.2
            },
            {
              "label": "grammar",
              "value": 89.9,
              "highlight": true
            }
          ]
        },
        {
          "label": "Qwen3-14B Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 92.3
            },
            {
              "label": "grammar",
              "value": 92.3,
              "highlight": true
            }
          ]
        },
        {
          "label": "Phi-4-mini Q4_K_M",
          "bars": [
            {
              "label": "free",
              "value": 77.7
            },
            {
              "label": "grammar",
              "value": 81.9,
              "highlight": true
            }
          ]
        }
      ]
    }
  },
  "attribution": "CORD-v2 (Park et al., 2019), CC BY 4.0."
}
