{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "normalized_query_v2_0_1",
  "title": "Normalized Query V2.0.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "user_message_raw",
    "message_in_scope",
    "scope_confidence",
    "contains_multiple_tasks",
    "fragments",
    "discarded_fragments",
    "global_notes"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "normalized_query_v2_0_1"
    },
    "user_message_raw": {
      "type": "string",
      "minLength": 1
    },
    "message_in_scope": {
      "type": "boolean"
    },
    "scope_confidence": {
      "type": "string",
      "enum": ["high", "medium", "low"]
    },
    "contains_multiple_tasks": {
      "type": "boolean"
    },
    "fragments": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "fragment_id",
          "raw_fragment_text",
          "normalized_fragment_text",
          "domain_relevance",
          "business_scope",
          "entity_hints",
          "account_hints",
          "document_hints",
          "register_hints",
          "time_scope",
          "flags",
          "candidate_labels",
          "confidence",
          "execution_readiness",
          "clarification_reason",
          "soft_assumption_used"
        ],
        "properties": {
          "fragment_id": { "type": "string", "minLength": 1 },
          "raw_fragment_text": { "type": "string", "minLength": 1 },
          "normalized_fragment_text": { "type": "string", "minLength": 1 },
          "domain_relevance": {
            "type": "string",
            "enum": ["in_scope", "out_of_scope", "unclear"]
          },
          "business_scope": {
            "type": "string",
            "enum": ["company_specific_accounting", "generic_accounting", "offtopic", "unclear"]
          },
          "entity_hints": {
            "type": "array",
            "items": { "type": "string" }
          },
          "account_hints": {
            "type": "array",
            "items": { "type": "string" }
          },
          "document_hints": {
            "type": "array",
            "items": { "type": "string" }
          },
          "register_hints": {
            "type": "array",
            "items": { "type": "string" }
          },
          "time_scope": {
            "type": "object",
            "additionalProperties": false,
            "required": ["type", "value", "confidence"],
            "properties": {
              "type": { "type": "string", "enum": ["explicit", "inferred", "missing"] },
              "value": { "type": ["string", "null"] },
              "confidence": { "type": "string", "enum": ["high", "medium", "low"] }
            }
          },
          "flags": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "has_multi_entity_scope",
              "asks_for_chain_explanation",
              "asks_for_ranking_or_top",
              "asks_for_period_summary",
              "asks_for_rule_check",
              "asks_for_anomaly_scan",
              "asks_for_exact_object_trace",
              "asks_for_evidence",
              "mentions_period_close_context"
            ],
            "properties": {
              "has_multi_entity_scope": { "type": "boolean" },
              "asks_for_chain_explanation": { "type": "boolean" },
              "asks_for_ranking_or_top": { "type": "boolean" },
              "asks_for_period_summary": { "type": "boolean" },
              "asks_for_rule_check": { "type": "boolean" },
              "asks_for_anomaly_scan": { "type": "boolean" },
              "asks_for_exact_object_trace": { "type": "boolean" },
              "asks_for_evidence": { "type": "boolean" },
              "mentions_period_close_context": { "type": "boolean" }
            }
          },
          "candidate_labels": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "heavy_analytical",
                "cross_entity",
                "drilldown_explain",
                "rule_based_account_control",
                "anomaly_probe",
                "period_close_risk",
                "ambiguous_human_query",
                "simple_factual"
              ]
            }
          },
          "confidence": {
            "type": "string",
            "enum": ["high", "medium", "low"]
          },
          "execution_readiness": {
            "type": "string",
            "enum": ["executable", "executable_with_soft_assumptions", "needs_clarification"]
          },
          "clarification_reason": {
            "type": ["string", "null"]
          },
          "soft_assumption_used": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["period_from_session_context", "company_scope_defaulted", "problem_scan_mode_enabled"]
            }
          }
        }
      }
    },
    "discarded_fragments": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["raw_fragment_text", "reason"],
        "properties": {
          "raw_fragment_text": { "type": "string", "minLength": 1 },
          "reason": { "type": "string", "minLength": 1 }
        }
      }
    },
    "global_notes": {
      "type": "object",
      "additionalProperties": false,
      "required": ["needs_clarification", "clarification_reason"],
      "properties": {
        "needs_clarification": { "type": "boolean" },
        "clarification_reason": { "type": ["string", "null"] }
      }
    }
  }
}

