{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/math.ratio/1.0.3/output.json",
  "title": "Ratio — success output",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "status",
    "capability_id",
    "engine",
    "inputs",
    "result",
    "result_detail",
    "calculation_version",
    "verification"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Requested tool id"
    },
    "status": {
      "const": "success"
    },
    "capability_id": {
      "const": "math.ratio"
    },
    "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": [
            "simplify",
            "proportion",
            "scale",
            "split",
            "compare",
            "convert"
          ]
        },
        "a": {
          "type": "string",
          "maxLength": 128
        },
        "b": {
          "type": "string",
          "maxLength": 128
        },
        "c": {
          "type": "string",
          "maxLength": 128
        },
        "d": {
          "type": "string",
          "maxLength": 128
        },
        "k": {
          "type": "string",
          "maxLength": 128
        },
        "total": {
          "type": "string",
          "maxLength": 128
        },
        "terms": {
          "enum": [
            2,
            3
          ]
        },
        "scaleOp": {
          "enum": [
            "multiply",
            "divide"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "const": "simplify"
              }
            }
          },
          "then": {
            "required": [
              "a",
              "b",
              "terms"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "proportion"
              }
            }
          },
          "then": {
            "required": []
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "scale"
              }
            }
          },
          "then": {
            "required": [
              "a",
              "b",
              "k",
              "terms",
              "scaleOp"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "split"
              }
            }
          },
          "then": {
            "required": [
              "a",
              "b",
              "total",
              "terms"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "compare"
              }
            }
          },
          "then": {
            "required": [
              "a",
              "b",
              "c",
              "d"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "convert"
              }
            }
          },
          "then": {
            "required": [
              "a",
              "b"
            ]
          }
        }
      ]
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "mode",
        "mode_label",
        "heading",
        "formula",
        "calculation_version",
        "inputs_summary",
        "explainer",
        "steps",
        "viz_terms",
        "viz_labels"
      ],
      "properties": {
        "value": {
          "type": "string"
        },
        "mode": {
          "enum": [
            "simplify",
            "proportion",
            "scale",
            "split",
            "compare",
            "convert"
          ]
        },
        "mode_label": {
          "type": "string"
        },
        "heading": {
          "type": "string"
        },
        "formula": {
          "type": "string"
        },
        "calculation_version": {
          "const": "1.0.3"
        },
        "inputs_summary": {
          "type": "string"
        },
        "explainer": {
          "type": "string"
        },
        "steps": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "ratio": {
          "type": "string"
        },
        "terms": {
          "type": "array",
          "minItems": 2,
          "maxItems": 3,
          "items": {
            "oneOf": [
              {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 1024
              }
            ]
          }
        },
        "terms_exact": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "gcf": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            }
          ]
        },
        "clearing_factor": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            }
          ]
        },
        "k": {
          "type": "string"
        },
        "scaleOp": {
          "type": "string"
        },
        "shares": {
          "type": "array",
          "minItems": 2,
          "maxItems": 3,
          "items": {
            "oneOf": [
              {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 1024
              }
            ]
          }
        },
        "solved": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            }
          ]
        },
        "solved_for": {
          "type": "string"
        },
        "A": {
          "type": "string"
        },
        "B": {
          "type": "string"
        },
        "C": {
          "type": "string"
        },
        "D": {
          "type": "string"
        },
        "equivalent": {
          "type": "boolean"
        },
        "part_to_part": {
          "type": [
            "string",
            "null"
          ]
        },
        "part_of_whole_A": {
          "type": [
            "string",
            "null"
          ]
        },
        "part_of_whole_B": {
          "type": [
            "string",
            "null"
          ]
        },
        "simplified": {
          "type": [
            "string",
            "null"
          ]
        },
        "viz_terms": {
          "type": "array",
          "minItems": 2,
          "maxItems": 3,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "value",
              "n",
              "d"
            ],
            "properties": {
              "value": {
                "type": "string"
              },
              "n": {
                "type": "string",
                "pattern": "^-?[0-9]+$"
              },
              "d": {
                "type": "string",
                "pattern": "^[1-9][0-9]*$"
              }
            }
          }
        },
        "viz_labels": {
          "type": "array",
          "minItems": 2,
          "maxItems": 3,
          "items": {
            "enum": [
              "A",
              "B",
              "C"
            ]
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "const": "simplify"
              }
            }
          },
          "then": {
            "required": [
              "ratio",
              "terms",
              "terms_exact",
              "gcf",
              "clearing_factor"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "scale"
              }
            }
          },
          "then": {
            "required": [
              "ratio",
              "terms",
              "k",
              "scaleOp"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "split"
              }
            }
          },
          "then": {
            "required": [
              "shares"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "proportion"
              }
            }
          },
          "then": {
            "required": [
              "solved",
              "solved_for",
              "A",
              "B",
              "C",
              "D"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "compare"
              }
            }
          },
          "then": {
            "required": [
              "equivalent"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "convert"
              }
            }
          },
          "then": {
            "required": [
              "part_to_part",
              "part_of_whole_A",
              "part_of_whole_B",
              "simplified"
            ]
          }
        }
      ]
    },
    "result_detail": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "formatted"
      ],
      "properties": {
        "value": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "value",
            "mode",
            "mode_label",
            "heading",
            "formula",
            "calculation_version",
            "inputs_summary",
            "explainer",
            "steps",
            "viz_terms",
            "viz_labels"
          ],
          "properties": {
            "value": {
              "type": "string"
            },
            "mode": {
              "enum": [
                "simplify",
                "proportion",
                "scale",
                "split",
                "compare",
                "convert"
              ]
            },
            "mode_label": {
              "type": "string"
            },
            "heading": {
              "type": "string"
            },
            "formula": {
              "type": "string"
            },
            "calculation_version": {
              "const": "1.0.3"
            },
            "inputs_summary": {
              "type": "string"
            },
            "explainer": {
              "type": "string"
            },
            "steps": {
              "type": "array",
              "minItems": 2,
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "ratio": {
              "type": "string"
            },
            "terms": {
              "type": "array",
              "minItems": 2,
              "maxItems": 3,
              "items": {
                "oneOf": [
                  {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1024
                  }
                ]
              }
            },
            "terms_exact": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "gcf": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                }
              ]
            },
            "clearing_factor": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                }
              ]
            },
            "k": {
              "type": "string"
            },
            "scaleOp": {
              "type": "string"
            },
            "shares": {
              "type": "array",
              "minItems": 2,
              "maxItems": 3,
              "items": {
                "oneOf": [
                  {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1024
                  }
                ]
              }
            },
            "solved": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                }
              ]
            },
            "solved_for": {
              "type": "string"
            },
            "A": {
              "type": "string"
            },
            "B": {
              "type": "string"
            },
            "C": {
              "type": "string"
            },
            "D": {
              "type": "string"
            },
            "equivalent": {
              "type": "boolean"
            },
            "part_to_part": {
              "type": [
                "string",
                "null"
              ]
            },
            "part_of_whole_A": {
              "type": [
                "string",
                "null"
              ]
            },
            "part_of_whole_B": {
              "type": [
                "string",
                "null"
              ]
            },
            "simplified": {
              "type": [
                "string",
                "null"
              ]
            },
            "viz_terms": {
              "type": "array",
              "minItems": 2,
              "maxItems": 3,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "value",
                  "n",
                  "d"
                ],
                "properties": {
                  "value": {
                    "type": "string"
                  },
                  "n": {
                    "type": "string",
                    "pattern": "^-?[0-9]+$"
                  },
                  "d": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]*$"
                  }
                }
              }
            },
            "viz_labels": {
              "type": "array",
              "minItems": 2,
              "maxItems": 3,
              "items": {
                "enum": [
                  "A",
                  "B",
                  "C"
                ]
              }
            }
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "simplify"
                  }
                }
              },
              "then": {
                "required": [
                  "ratio",
                  "terms",
                  "terms_exact",
                  "gcf",
                  "clearing_factor"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "scale"
                  }
                }
              },
              "then": {
                "required": [
                  "ratio",
                  "terms",
                  "k",
                  "scaleOp"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "split"
                  }
                }
              },
              "then": {
                "required": [
                  "shares"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "proportion"
                  }
                }
              },
              "then": {
                "required": [
                  "solved",
                  "solved_for",
                  "A",
                  "B",
                  "C",
                  "D"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "compare"
                  }
                }
              },
              "then": {
                "required": [
                  "equivalent"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "mode": {
                    "const": "convert"
                  }
                }
              },
              "then": {
                "required": [
                  "part_to_part",
                  "part_of_whole_A",
                  "part_of_whole_B",
                  "simplified"
                ]
              }
            }
          ]
        },
        "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,
      "required": [
        "tier",
        "engine_tested",
        "expert_reviewed",
        "source_checked",
        "reviewed_by",
        "reviewer_role",
        "last_reviewed",
        "verification_revision",
        "verified_scope",
        "evidence_digest"
      ],
      "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"
          ]
        },
        "citation_kind": {
          "type": "string"
        },
        "expert_review": {
          "type": "string"
        },
        "domain_review": {
          "type": "string"
        },
        "calculation_version": {
          "type": "string"
        },
        "calc_tests": {
          "type": [
            "string",
            "null"
          ]
        },
        "tests_passed": {
          "type": [
            "integer",
            "null"
          ]
        },
        "tests_total": {
          "type": [
            "integer",
            "null"
          ]
        },
        "artifact_contract": {
          "type": [
            "string",
            "null"
          ]
        },
        "trust_peek": {
          "type": [
            "string",
            "null"
          ]
        },
        "verification_revision": {
          "type": "string"
        },
        "verified_scope": {
          "type": "string"
        },
        "evidence_digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "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"
        }
      }
    }
  }
}
