{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/math.sum/1.0.3/output.json",
  "title": "Sum / addition — success output",
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "resultBranch0Result": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": {
          "const": "sum"
        },
        "algorithm": {
          "enum": [
            "exact-decimal",
            "neumaier"
          ]
        },
        "count": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000
        },
        "values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "number"
          }
        },
        "tokens": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "^[+-]?(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$"
          }
        },
        "sum": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "sumStr": {
          "type": "string"
        },
        "mean": {
          "type": "number"
        },
        "mean_exact": {
          "type": "boolean"
        },
        "mean_rational_exact": {
          "type": "boolean"
        },
        "mean_numeric_approximate": {
          "type": "boolean"
        },
        "sum_numeric_approximate": {
          "type": "boolean"
        },
        "formula": {
          "type": "string"
        },
        "heading": {
          "type": "string"
        },
        "mode_label": {
          "type": "string"
        },
        "explainer": {
          "type": "string"
        },
        "inputs_summary": {
          "type": "string"
        },
        "calculation_version": {
          "const": "1.0.3"
        },
        "warnings": {
          "type": "array",
          "maxItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "code",
              "message",
              "example",
              "compact",
              "parts"
            ],
            "properties": {
              "code": {
                "const": "THOUSANDS_SEPARATOR_AMBIGUITY"
              },
              "message": {
                "type": "string"
              },
              "example": {
                "type": "string"
              },
              "compact": {
                "type": "string"
              },
              "parts": {
                "type": "array",
                "minItems": 2,
                "items": {
                  "type": "string"
                }
              }
            }
          }
        },
        "warning": {
          "type": "string"
        },
        "display": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "value",
            "sum",
            "mean"
          ],
          "properties": {
            "value": {
              "type": "string"
            },
            "sum": {
              "type": "string"
            },
            "mean": {
              "type": "string"
            }
          }
        },
        "work": {
          "type": "null"
        },
        "chart": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "number"
          }
        },
        "mean_num": {
          "type": [
            "string",
            "null"
          ]
        },
        "mean_den": {
          "type": [
            "string",
            "null"
          ]
        },
        "mean_display": {
          "type": "string"
        },
        "mean_approx": {
          "type": "boolean"
        },
        "chart_model": {
          "enum": [
            "exact-decimal",
            "binary64"
          ]
        }
      },
      "required": [
        "mode",
        "algorithm",
        "count",
        "values",
        "tokens",
        "sum",
        "value",
        "sumStr",
        "mean",
        "mean_exact",
        "mean_rational_exact",
        "mean_numeric_approximate",
        "sum_numeric_approximate",
        "formula",
        "heading",
        "mode_label",
        "explainer",
        "inputs_summary",
        "calculation_version",
        "warnings",
        "display",
        "work",
        "chart",
        "mean_num",
        "mean_den",
        "mean_display",
        "mean_approx",
        "chart_model"
      ]
    },
    "resultBranch1Result": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": {
          "const": "long"
        },
        "algorithm": {
          "const": "long-addition"
        },
        "count": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32
        },
        "values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "number"
          }
        },
        "tokens": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "^[+-]?(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$"
          }
        },
        "sum": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "sumStr": {
          "type": "string"
        },
        "mean": {
          "type": "number"
        },
        "mean_exact": {
          "type": "boolean"
        },
        "mean_rational_exact": {
          "type": "boolean"
        },
        "mean_numeric_approximate": {
          "type": "boolean"
        },
        "sum_numeric_approximate": {
          "type": "boolean"
        },
        "formula": {
          "type": "string"
        },
        "heading": {
          "type": "string"
        },
        "mode_label": {
          "type": "string"
        },
        "explainer": {
          "type": "string"
        },
        "inputs_summary": {
          "type": "string"
        },
        "calculation_version": {
          "const": "1.0.3"
        },
        "warnings": {
          "type": "array",
          "maxItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "code",
              "message",
              "example",
              "compact",
              "parts"
            ],
            "properties": {
              "code": {
                "const": "THOUSANDS_SEPARATOR_AMBIGUITY"
              },
              "message": {
                "type": "string"
              },
              "example": {
                "type": "string"
              },
              "compact": {
                "type": "string"
              },
              "parts": {
                "type": "array",
                "minItems": 2,
                "items": {
                  "type": "string"
                }
              }
            }
          }
        },
        "warning": {
          "type": "string"
        },
        "display": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "value",
            "sum"
          ],
          "properties": {
            "value": {
              "type": "string"
            },
            "sum": {
              "type": "string"
            }
          }
        },
        "work": {
          "type": "string"
        },
        "chart": {
          "type": "null"
        }
      },
      "required": [
        "mode",
        "algorithm",
        "count",
        "values",
        "tokens",
        "sum",
        "value",
        "sumStr",
        "mean",
        "mean_exact",
        "mean_rational_exact",
        "mean_numeric_approximate",
        "sum_numeric_approximate",
        "formula",
        "heading",
        "mode_label",
        "explainer",
        "inputs_summary",
        "calculation_version",
        "warnings",
        "display",
        "work",
        "chart"
      ]
    },
    "calcResult": {
      "oneOf": [
        {
          "$ref": "#/$defs/resultBranch0Result"
        },
        {
          "$ref": "#/$defs/resultBranch1Result"
        }
      ]
    }
  },
  "required": [
    "status",
    "capability_id",
    "engine",
    "inputs",
    "result",
    "result_detail",
    "calculation_version",
    "verification",
    "review"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Requested tool id"
    },
    "status": {
      "const": "success"
    },
    "capability_id": {
      "const": "math.sum"
    },
    "tool": {
      "type": "string",
      "description": "Requested tool id"
    },
    "engine": {
      "type": "string"
    },
    "inputs": {
      "description": "Normalized calculation inputs (aliases resolved to canonical form)",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode"
      ],
      "properties": {
        "mode": {
          "enum": [
            "sum",
            "long"
          ]
        },
        "sumInput": {
          "type": "string",
          "minLength": 1,
          "maxLength": 65536
        },
        "values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10000,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "^[+-]?(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$"
          }
        }
      },
      "oneOf": [
        {
          "required": [
            "sumInput"
          ]
        },
        {
          "required": [
            "values"
          ]
        }
      ]
    },
    "result": {
      "$ref": "#/$defs/calcResult"
    },
    "result_detail": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "formatted"
      ],
      "properties": {
        "value": {
          "$ref": "#/$defs/calcResult"
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "formatted": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "formula": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "string"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string"
            },
            "expression": {
              "type": "string"
            },
            "label": {
              "type": "string"
            }
          }
        }
      ]
    },
    "assumptions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "severity": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "suggestion": {
            "type": "string"
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "description": "Computational verification under CVP. Review-policy tiers live on `review`, not here.",
      "required": [
        "cvp"
      ],
      "properties": {
        "cvp": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "protocol",
            "profile",
            "verified_scope",
            "verification_revision",
            "evidence_digest"
          ],
          "properties": {
            "status": {
              "type": "string",
              "description": "CVP verification status (e.g. VERIFIED)"
            },
            "protocol": {
              "type": "string",
              "description": "CVP protocol id, e.g. 1.0.0-proposed"
            },
            "profile": {
              "type": "string"
            },
            "verified_scope": {
              "type": "string"
            },
            "verification_revision": {
              "type": [
                "string",
                "null"
              ]
            },
            "evidence_digest": {
              "type": [
                "string",
                "null"
              ]
            },
            "production": {
              "type": [
                "string",
                "null"
              ],
              "description": "Production freshness, e.g. CURRENT"
            },
            "evidence": {
              "type": "string",
              "format": "uri"
            }
          }
        }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tier",
        "engine_tested",
        "expert_reviewed",
        "source_checked",
        "reviewed_by",
        "reviewer_role",
        "last_reviewed"
      ],
      "properties": {
        "tier": {
          "type": "string",
          "enum": [
            "candidate",
            "engine_tested",
            "internally_reviewed",
            "expert_verified"
          ]
        },
        "engine_tested": {
          "type": "boolean"
        },
        "expert_reviewed": {
          "type": "boolean"
        },
        "internally_reviewed": {
          "type": "boolean"
        },
        "review_kind": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_checked": {
          "type": "boolean"
        },
        "reviewed_by": {
          "type": [
            "string",
            "null"
          ]
        },
        "reviewer_role": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_reviewed": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "tier": {
                "const": "expert_verified"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "expert_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              },
              "reviewed_by": {
                "type": "string",
                "minLength": 1
              },
              "reviewer_role": {
                "type": "string",
                "minLength": 1
              },
              "last_reviewed": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "internally_reviewed"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "internally_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "engine_tested"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              }
            }
          }
        }
      ]
    },
    "calculation_version": {
      "type": "string",
      "const": "1.0.3"
    },
    "api_version": {
      "type": "string"
    },
    "api_contract_version": {
      "type": "string"
    },
    "spec_version": {
      "type": "string"
    },
    "page": {
      "type": [
        "string",
        "null"
      ],
      "description": "Canonical calculator page URL"
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema_input": {
          "type": "string",
          "format": "uri"
        },
        "schema_output": {
          "type": "string",
          "format": "uri"
        },
        "evidence": {
          "type": "string",
          "format": "uri"
        },
        "openapi": {
          "type": "string",
          "format": "uri"
        },
        "capabilities": {
          "type": "string",
          "format": "uri"
        },
        "mcp": {
          "type": "string",
          "format": "uri"
        }
      }
    }
  }
}
