{}
StrictJSON

Library / Receipt Parser

Extraction

Receipt Parser

Receipts are the messiest documents in business automation: a total that already includes tax, a tax line that does not add up to the printed rate, line items split across two lines, dates written as 03/04/2026, and amounts with or without a currency symbol. This prompt turns a raw receipt — pasted text or OCR output — into one strict JSON object: invoice number, issue date in ISO format, vendor name, total tax, grand total, and every line item with name, quantity and price. The schema forces numbers to stay numbers (never "$12.50" as a string), requires every field, and only allows an empty line_items array when the receipt truly has no lines. Use it to feed expense tools, accounting imports, or receipt-scanning apps without writing a parser for every store layout.

Optimized System Prompt

You are a precise receipt extraction engine. Read the provided receipt text and return ONLY a valid JSON object matching the schema below. Do not add explanations, markdown, or extra fields. Every field is required: extract the best value printed on the receipt and never invent a value that is not printed on the receipt. Never use null or an empty string for a required field. Dates must be ISO 8601 (YYYY-MM-DD). All amounts are numbers with two decimals, no currency symbols. line_items must contain one object per printed line, with name, qty, and price; use an empty array only if the receipt has no line items.

Raw JSON Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Receipt",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "invoice_number",
    "issue_date",
    "vendor_name",
    "total_tax",
    "grand_total",
    "line_items"
  ],
  "properties": {
    "invoice_number": {
      "type": "string",
      "minLength": 1,
      "description": "Invoice or receipt number as printed."
    },
    "issue_date": {
      "type": "string",
      "format": "date",
      "minLength": 1,
      "description": "Issue date in YYYY-MM-DD format."
    },
    "vendor_name": {
      "type": "string",
      "minLength": 1
    },
    "total_tax": {
      "type": "number",
      "minimum": 0
    },
    "grand_total": {
      "type": "number",
      "minimum": 0
    },
    "line_items": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "qty",
          "price"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "qty": {
            "type": "number"
          },
          "price": {
            "type": "number",
            "minimum": 0
          }
        }
      }
    }
  }
}

Validation Code — Zod (TypeScript)

import { z } from "zod";

export const LineItemSchema = z.object({
  name: z.string().min(1),
  qty: z.number(),
  price: z.number().min(0),
});

export const ReceiptSchema = z.object({
  invoice_number: z.string().min(1),
  issue_date: z.string().min(1).describe("Issue date, YYYY-MM-DD"),
  vendor_name: z.string().min(1),
  total_tax: z.number().min(0),
  grand_total: z.number().min(0),
  line_items: z.array(LineItemSchema),
});

export type Receipt = z.infer<typeof ReceiptSchema>;

Validation Code — Pydantic v2 (Python)

from pydantic import BaseModel, Field
from datetime import date


class LineItem(BaseModel):
    name: str = Field(..., min_length=1)
    qty: float
    price: float = Field(..., ge=0)


class Receipt(BaseModel):
    invoice_number: str = Field(..., min_length=1)
    issue_date: date
    vendor_name: str = Field(..., min_length=1)
    total_tax: float = Field(..., ge=0)
    grand_total: float = Field(..., ge=0)
    line_items: list[LineItem] = []

Try it in the StrictJSON tool → · ← Back to the Library