{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/anchord-ai/json-schema/anchord-ai-batch-result-schema.json",
  "title": "BatchResult",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/anchord-ai-openapi.yaml#/components/schemas/BatchResult",
  "type": "object",
  "required": [
    "client_ref",
    "status",
    "safe_to_write"
  ],
  "properties": {
    "client_ref": {
      "type": "string"
    },
    "status": {
      "$ref": "#/$defs/ResolveStatus"
    },
    "entity_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "entity": {
      "anyOf": [
        {
          "$ref": "#/$defs/EntityRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "confidence": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 1
    },
    "safe_to_write": {
      "type": "boolean"
    },
    "targets": {
      "$ref": "#/$defs/TargetMap"
    },
    "missing_targets": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "attempt_id": {
      "type": "string",
      "format": "uuid"
    },
    "candidates": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Candidate"
      }
    }
  },
  "$defs": {
    "Candidate": {
      "type": "object",
      "required": [
        "entity_id",
        "confidence"
      ],
      "properties": {
        "entity_id": {
          "type": "string",
          "format": "uuid"
        },
        "source_record_id": {
          "type": "string",
          "format": "uuid"
        },
        "system": {
          "type": "string"
        },
        "object_type": {
          "type": "string"
        },
        "object_id": {
          "type": "string"
        },
        "integration_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "reasons": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "EntityKind": {
      "type": "string",
      "enum": [
        "company",
        "person"
      ]
    },
    "EntityRef": {
      "type": "object",
      "required": [
        "id",
        "kind"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "kind": {
          "$ref": "#/$defs/EntityKind"
        }
      }
    },
    "LinkSource": {
      "type": "string",
      "enum": [
        "resolution",
        "auto_resolve",
        "reconcile",
        "manual",
        "merge",
        "api",
        "manual_review"
      ],
      "description": "How a source record was linked to an entity (provenance). resolution = query-time resolve, auto_resolve = post-ingest exact match, reconcile = deferred fuzzy reconciliation, manual = user action, merge = entity merge/dedup, api = public link API, manual_review = review confirm.\n"
    },
    "ResolveStatus": {
      "type": "string",
      "enum": [
        "resolved",
        "needs_review",
        "not_found"
      ]
    },
    "TargetEntry": {
      "type": "object",
      "required": [
        "object_type",
        "object_id",
        "source_record_id"
      ],
      "properties": {
        "object_type": {
          "type": "string"
        },
        "object_id": {
          "type": "string"
        },
        "source_record_id": {
          "type": "string",
          "format": "uuid"
        },
        "linked_by": {
          "$ref": "#/$defs/LinkSource"
        },
        "confidence": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "integration_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "integration_label": {
          "type": [
            "string",
            "null"
          ]
        },
        "integration_external_id": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "TargetMap": {
      "type": "object",
      "description": "Keys are system names (hubspot, salesforce, stripe, etc.). Values are arrays of target records from that system.\n",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/TargetEntry"
        }
      }
    }
  }
}