{
  "id": "ts-1",
  "title": "Trust Score: How do I filter CIQ queries by a subject's trust score threshold?",
  "description": "Configure a Trust Score Profile for Person, ingest two Persons with different metadata quality via the Capture API, let the profile compute a _TrustScore for each, then run a CIQ query that returns the caller's own profile only when their _final_score is at or above the requested threshold.",
  "category": "TrustScore",
  "tags": [
    "Trust Score",
    "Trust Score Profile",
    "Capture",
    "ContX IQ Policy",
    "ContX IQ Query",
    "_TrustScore Node",
    "Data Quality",
    "subject.trust_score._final_score"
  ],
  "api": "Trust Score",
  "language": "Json",
  "lastUpdated": "2026-05-20",
  "openApiEndpoints": [
    "/configs/v1/trust-score-profiles",
    "/capture/v1/nodes",
    "/configs/v1/authorization-policies",
    "/configs/v1/knowledge-queries",
    "/contx-iq/v1/execute"
  ],
  "relatedGuides": [
    "/guides/guide-trust-score",
    "/guides/guide-contx-iq"
  ],
  "commonErrors": [
    {
      "code": "200",
      "message": "data array always empty even for a trustworthy subject",
      "solution": "The profile may not have run yet, so subject.trust_score._final_score is undefined and the filter rejects every row. With schedule THREE_HOURS the first pass can take up to 3 hours after profile creation - retry the execute after a scoring cycle."
    },
    {
      "code": "200",
      "message": "trust_score._final_score missing from response",
      "solution": "Add subject.trust_score._final_score (or subject.trust_score.*) to allowed_reads on the policy. The runtime hides any attribute the policy does not declare."
    },
    {
      "code": "400",
      "message": "node_classification does not exist",
      "solution": "The Trust Score profile is scoped to a specific node label. Use the exact label that the Capture API ingested under (case-sensitive)."
    }
  ],
  "summary": "End-to-end demonstration that the Trust Score lives on the node as a regular property and can be filtered on inside a CIQ policy.\n\nPipeline:\n1. Trust Score Profile (REST): Create a profile scoped to node_classification = \"Person\" with weighted dimensions (verification, origin, freshness).\n2. Capture (REST): Ingest two Person nodes. One carries rich metadata (verified_time, source = \"id-verifier.gov\"); the other has only a self-attested source. The metadata is what the dimensions evaluate.\n3. Scoring runs on the configured schedule: each Person gets a _TrustScore node attached via _HAS, with property _final_score plus one property per active dimension. The score IS a node in the IKG - every CIQ traversal can see it as subject.trust_score.<dim>.\n4. CIQ filter (POST /contx-iq/v1/execute): the policy filter requires subject.trust_score._final_score > 0.66 (a fixed threshold baked into the policy). The high-metadata Person clears the bar; the self-attested one does not.\n\nEffect: data quality becomes a first-class authorization input - the policy admits a subject only when its computed trust score clears the threshold.",
  "usecase": "Scenario: A KYC-style portal returns a Person's profile only if their underlying identity data clears a freshness/verification bar. The policy hardcodes the threshold at 0.66; the subject is the caller, bound through subject.external_id = $token.sub.\n\nPersons captured (relevant metadata only):\n- Person(knightrider) - email + name carry verified_time = \"2026-05-10T08:00:00Z\" and source = \"id-verifier.gov\".\n- Person(satchmo)     - email + name carry source = \"user-self-attested\" only.\n\nAfter scoring (THREE_HOURS), the IKG has:\n- (knightrider) -[:_HAS]-> _TrustScore { _final_score: 0.83, verification: 1.0, origin: 0.75, freshness: 0.74 }\n- (satchmo)     -[:_HAS]-> _TrustScore { _final_score: 0.42, verification: 0.0, origin: 0.4, freshness: 0.85 }\n\nCIQ executions:\n- Executed with knightrider's token -> 0.83 > 0.66 -> returns the profile, including subject.trust_score._final_score = 0.83.\n- Executed with satchmo's token -> 0.42 is not > 0.66 -> returns an empty data array. satchmo exists, but the trust threshold isn't met.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating the Trust Score Profile, the CIQ policy, and the Knowledge Query.\n- AppAgent credentials: For ingesting Person nodes via the Capture API and for executing the query.\n- Bearer token: the subject is a Person, so /contx-iq/v1/execute needs a third-party bearer token alongside X-IK-ClientKey. The subject is the token's sub claim.\n- Patience: scores are computed on the schedule (THREE_HOURS in this example). The first run produces the initial _TrustScore nodes; subsequent runs update them.\n\nRequired API access:\n- POST /configs/v1/trust-score-profiles\n- POST /capture/v1/nodes\n- POST /configs/v1/authorization-policies\n- POST /configs/v1/knowledge-queries\n- POST /contx-iq/v1/execute",
  "steps": "Step 1: Create the Trust Score Profile for Person\n- Schedule: THREE_HOURS (allowed values: THREE_HOURS, SIX_HOURS, TWELVE_HOURS, DAILY). Pick longer intervals for stable identity data.\n- Dimensions: VERIFICATION, ORIGIN, FRESHNESS weighted 1 each; COMPLETENESS and VALIDITY present but weight 0 so they don't influence _final_score. Weights must be between 0 and 1.\n- node_classification: \"Person\" - only Person nodes are scored by this profile.\n\nStep 2: Capture Persons (with the metadata the profile cares about)\n- Each scored property should carry the metadata fields the profile uses (property.metadata is a single object: source, verified_time, assurance_level, custom_metadata).\n  - verification dimension reads property.metadata.verified_time.\n  - origin dimension reads property.metadata.source.\n  - freshness dimension uses node + property update times.\n- Two contrasting Persons make the threshold visible: a high-quality one (DMV-sourced, recently verified) and a self-attested one.\n- After capture, scoring runs on the profile schedule; each Person gets a _TrustScore node and the value becomes readable as subject.trust_score.* in CIQ. There is no synchronous read - wait for the scheduled pass, then run the query below.\n\nStep 3: Create the CIQ Policy\n- The condition filter ANDs subject.external_id = $token.sub with subject.trust_score._final_score > 0.66 (the threshold is fixed in the policy).\n- allowed_reads exposes the trust score so the response can show why the row was accepted.\n\nStep 4: Create and Execute the Knowledge Query\n- The query simply returns the subject's own fields + subject.trust_score._final_score.\n- Execute once with each person's token (knightrider clears the bar, satchmo does not); no input parameters are needed.\n- Bearer token + X-IK-ClientKey are required as for any Person-subject CIQ call.",
  "graph": {
    "caption": "The graph the example runs on: 2 nodes (2 Person), no relationships. Hover a node for its properties.",
    "nodes": [
      {
        "external_id": "knightrider",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "knightrider@demo.com"
          },
          {
            "type": "name",
            "value": "Michael Knight"
          }
        ]
      },
      {
        "external_id": "satchmo",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "satchmo@demo.com"
          },
          {
            "type": "name",
            "value": "Louis Armstrong"
          }
        ]
      }
    ],
    "relationships": []
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Trust Score Profile config for Person (flat REST body). node_classification controls which nodes get scored; schedule is one of THREE_HOURS/SIX_HOURS/TWELVE_HOURS/DAILY; each dimensions[].weight is between 0 and 1 (weight = 0 means computed-but-ignored).",
      "filename": "POST https://eu.api.indykite.com/configs/v1/trust-score-profiles",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "name": "person-trust-score-profile",
        "display_name": "Person Trust Score Profile",
        "description": "Trust Score profile for Person nodes. Combines verification, origin and freshness with equal weights; completeness and validity are present but weighted 0 (still computed, not used in _final_score).",
        "node_classification": "Person",
        "schedule": "THREE_HOURS",
        "dimensions": [
          {
            "name": "VERIFICATION",
            "weight": 1
          },
          {
            "name": "ORIGIN",
            "weight": 1
          },
          {
            "name": "FRESHNESS",
            "weight": 1
          },
          {
            "name": "COMPLETENESS",
            "weight": 0
          },
          {
            "name": "VALIDITY",
            "weight": 0
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "Capture two contrasting Person nodes. The metadata object on each property is the actual input to the scoring dimensions - verified_time, source, and update times.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/nodes/",
      "language": "Json",
      "ingest": {
        "nodes": [
          {
            "external_id": "knightrider",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "knightrider@demo.com",
                "metadata": {
                  "verified_time": "2026-05-10T08:00:00Z",
                  "source": "id-verifier.gov"
                }
              },
              {
                "type": "name",
                "value": "Michael Knight",
                "metadata": {
                  "verified_time": "2026-05-10T08:00:00Z",
                  "source": "id-verifier.gov"
                }
              }
            ]
          },
          {
            "external_id": "satchmo",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "satchmo@demo.com",
                "metadata": {
                  "source": "user-self-attested"
                }
              },
              {
                "type": "name",
                "value": "Louis Armstrong",
                "metadata": {
                  "source": "user-self-attested"
                }
              }
            ]
          }
        ]
      }
    },
    {
      "step": "Step 3",
      "description": "CIQ Policy. The trust score appears on the subject just like any other node attribute via subject.trust_score._final_score, so it can be ANDed into the regular filter.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "Person"
        },
        "condition": {
          "cypher": "MATCH (subject:Person)",
          "filter": [
            {
              "operator": "AND",
              "operands": [
                {
                  "operator": "=",
                  "attribute": "subject.external_id",
                  "value": "$token.sub"
                },
                {
                  "operator": ">",
                  "attribute": "subject.trust_score._final_score",
                  "value": 0.66
                }
              ]
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "subject.external_id",
            "subject.property.email",
            "subject.property.name",
            "subject.trust_score._final_score"
          ]
        }
      }
    },
    {
      "description": "Request to create the policy.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/authorization-policies",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "CIQ policy that returns the requested Person record ONLY when its computed Trust Score _final_score is above the hardcoded threshold (0.66). The Trust Score Profile must already be active for node_classification = Person; otherwise subject.trust_score._final_score is undefined and the filter rejects every row.",
        "display_name": "policy - person with trust score filter",
        "name": "policy-trust-score-filter",
        "policy": "{\"meta\":{\"policy_version\":\"1.0-ciq\"},\"subject\":{\"type\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)\",\"filter\":[{\"operator\":\"AND\",\"operands\":[{\"operator\":\"=\",\"attribute\":\"subject.external_id\",\"value\":\"$token.sub\"},{\"operator\":\">\",\"attribute\":\"subject.trust_score._final_score\",\"value\":0.66}]}]},\"allowed_reads\":{\"nodes\":[\"subject.external_id\",\"subject.property.email\",\"subject.property.name\",\"subject.trust_score._final_score\"]}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "step": "Step 4",
      "description": "Knowledge Query - returns the subject's own profile plus subject.trust_score._final_score.",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "subject.external_id",
          "subject.property.email",
          "subject.property.name",
          "subject.trust_score._final_score"
        ]
      }
    },
    {
      "description": "Request to create the Knowledge Query.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/knowledge-queries",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "Returns the requested Person's profile but ONLY if their Trust Score _final_score is above the policy threshold (0.66). The trust score itself is included in the response so you can see why a subject was accepted or excluded.",
        "display_name": "knowledge query - my profile if trustworthy",
        "name": "kq-my-profile-trusted",
        "policy_id": "your_policy_gid",
        "query": "{\"nodes\":[\"subject.external_id\",\"subject.property.email\",\"subject.property.name\",\"subject.trust_score._final_score\"]}",
        "status": "ACTIVE"
      }
    },
    {
      "description": "Execute with Knight Rider's token (high-quality data). His _final_score 0.83 clears the policy's 0.66 threshold.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "your_query_gid_or_name",
        "input_params": {}
      }
    },
    {
      "description": "Response: profile returned, _final_score = 0.83 is included as a regular field in the result row.",
      "filename": "response_trusted.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "subject.external_id": "knightrider",
              "subject.property.email": "knightrider@demo.com",
              "subject.property.name": "Michael Knight",
              "subject.trust_score._final_score": 0.83
            }
          }
        ]
      }
    },
    {
      "description": "Execute with Satchmo's token (self-attested data). His _final_score 0.42 does not clear the 0.66 threshold.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "your_query_gid_or_name",
        "input_params": {}
      }
    },
    {
      "description": "Response: empty data array. The Person exists but the trust score is below the threshold, so the filter drops the row.",
      "filename": "response_rejected.json",
      "language": "Json",
      "ingest": {
        "data": []
      }
    }
  ],
  "links": {
    "html": "/resources/ts-1",
    "markdown": "/resources/ts-1.md",
    "openApi": "https://openapi.indykite.com/"
  }
}