{
  "type": "object",
  "properties": {
    "reference": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Extract the quote reference from the input text. Copy the complete text between single quotes exactly, preserving case and punctuation, without the surrounding quotes."
    },
    "variables": {
      "type": "object",
      "description": "Extract the quantities and amounts from the prose. Copy each numeric literal verbatim as a string; identify its role from the wording. Do not invent values. Amounts are written as whole cents.",
      "properties": {
        "quantity": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "maxLength": 12,
          "description": "Copy the number of items being purchased."
        },
        "unit_price_cents": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "maxLength": 12,
          "description": "Copy the price for one item before any extra charge or discount, in cents."
        },
        "adjustment_cents": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "maxLength": 12,
          "description": "Copy the stated charge or discount amount in cents. The formula determines whether to add or subtract it and whether it applies once or per item."
        }
      },
      "required": [
        "quantity",
        "unit_price_cents",
        "adjustment_cents"
      ],
      "additionalProperties": false
    },
    "formula": {
      "type": "array",
      "minItems": 2,
      "maxItems": 4,
      "description": "Build the arithmetic calculation that answers the question, in order. Each step applies its operator to left and right, then records the exact result. Reference the extracted variable names or an earlier result: step_1 is the first step's result, step_2 the second, and so on. Choose the operations and their order from the wording. Do not reference the current step or a future step. Use all three extracted variables. Every step before the final step must feed a later step; return the complete total, not a subtotal.",
      "items": {
        "type": "object",
        "properties": {
          "operator": {
            "type": "string",
            "enum": [
              "add",
              "subtract",
              "multiply",
              "divide"
            ]
          },
          "left": {
            "type": "string",
            "enum": [
              "quantity",
              "unit_price_cents",
              "adjustment_cents",
              "step_1",
              "step_2",
              "step_3"
            ]
          },
          "right": {
            "type": "string",
            "enum": [
              "quantity",
              "unit_price_cents",
              "adjustment_cents",
              "step_1",
              "step_2",
              "step_3"
            ]
          },
          "result": {
            "type": "number",
            "description": "The exact arithmetic result of this step, without rounding."
          }
        },
        "required": [
          "operator",
          "left",
          "right",
          "result"
        ],
        "additionalProperties": false
      }
    },
    "result_cents": {
      "type": "integer",
      "description": "The final step's result, in whole cents."
    }
  },
  "required": [
    "reference",
    "variables",
    "formula",
    "result_cents"
  ],
  "additionalProperties": false
}
