Records
The cognite_data_quality._records module provides helpers for posting validation results to the CDF Records API and for constructing both DataQualityValidationRecord and RuleEngineResult payloads.
Validation results written by run_validation() (when post_to_records=True) and by the deployed Cognite Functions all use these helpers (function handlers also use _function_code/common/records_api.py and type-specific builders such as edge_existence_records.py). You typically do not call these directly — use run_validation() or the deployed function instead.
Containers
| Container | Written by |
|---|---|
DataQualityValidationRecord |
All validation handlers — one record per focus node per run (plus grouped uniqueness summaries) |
RuleEngineResult |
All validation handlers — one record per dqs:RuleEngineResult subject CONSTRUCTed by sh:rule blocks |
Both containers are provisioned by deploy_validation_infrastructure() in the same Records space (default dataQuality). Deploy also ensures record views of the same externalIds (version v1) with streamId set, applied together and not attached to a data model. If the stream is not created yet, view apply is skipped with a warning and the rest of deploy continues. They share the same stream by default; set records.rule_engine_stream_id in settings.yaml to route inference results to a separate stream.
Records use a stable externalId (no jobRunId in the key). The write endpoint is chosen at runtime from the stream's mutability: mutable streams (BasicLiveData) upsert to one record per key (current state), immutable streams (BasicArchive) ingest every run (history). Set records.stream_type to a CDF template name (e.g. BasicArchive, BasicLiveData) for new stream creation; at runtime the actual type is auto-detected. See Records output for details.
DataQualityValidationRecord includes validationType / groupViolationType for uniqueness overflow/pass markers, and edge existence uses the same container with relation-scoped stable keys (dq_{ruleSetId}_edge_{relationProperty}_{instanceSpace}_...). See Records output for the full property table, externalId patterns, edge records, and query examples.
On 0.5.x, record views over these containers are the Flows listing surface (view + stream). Customer instance views can opt in to reverse navigation through focusNodeInstance — see Reverse navigation. Record views are not in data models yet and are not GraphQL / instances.query sources.
cognite_data_quality._records
DataQualityRecord
Bases: BaseModel
DMS instance upsert payload for a single validated instance.
Attributes:
| Name | Type | Description |
|---|---|---|
space |
str
|
Destination DMS space for this record. |
external_id |
str
|
External ID of the record instance. |
properties |
dict
|
Dict of property values to write to the Records container. |
Source code in cognite_data_quality/_records.py
RecordsConfig
Bases: BaseModel
Records API coordinates and rule set metadata for a validation run.
Attributes:
| Name | Type | Description |
|---|---|---|
stream_id |
str | None
|
External ID of the Records API stream to ingest into.
Set to |
rule_set_id |
str
|
Identifier for the SHACL rule set being applied (written to every record). |
rule_set_version |
str
|
Version string of the rule set (written to every record). |
data_domain_external_id |
str | None
|
Optional data domain tag written to each record for filtering in the validation dashboard. |
records_space |
str
|
CDF DMS space that hosts the validation records
container. Default: |
records_container |
str
|
External ID of the DMS container that stores
records. Default: |
use_instance_space |
bool
|
Write each record into the same space as the
validated instance instead of records_space. Default: |
record_space |
str | None
|
Explicit destination space, overriding records_space
when use_instance_space is |
Source code in cognite_data_quality/_records.py
Violation
Bases: BaseModel
A single constraint violation extracted from a SHACL validation report.
All fields map directly to SHACL result properties and may be None
when the SHACL engine did not produce that property for a given result.
Attributes:
| Name | Type | Description |
|---|---|---|
focusNode |
str | None
|
URI of the node that failed the constraint. |
resultMessage |
str | None
|
Human-readable violation message from |
resultSeverity |
str | None
|
Severity URI (e.g. |
sourceConstraintComponent |
str | None
|
SHACL constraint component that raised the
violation (e.g. |
resultPath |
str | None
|
Property path that caused the violation. |
value |
str | None
|
The offending value, if any. |
sourceShape |
str | None
|
External ID / URI of the shape that contains the violated constraint. |
sourceConstraint |
str | None
|
The specific constraint within the shape. |
dimension |
str | None
|
Data quality dimension label (Completeness, Validity, etc.). |
shaclName |
str | None
|
Human-readable |
Source code in cognite_data_quality/_records.py
build_record_view_items(*, space, validation_container, rule_engine_container, validation_stream_id, rule_engine_stream_id, version=RECORD_VIEW_VERSION)
Build the two record-view apply payloads (validation + rule engine) for one views.apply.
Source code in cognite_data_quality/_records.py
build_records(instances, violations, *, job_run_id, records_config, namespace_base)
Build Records API payloads for all instances.
Source code in cognite_data_quality/_records.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
build_schema_issue_records(schema_issues, *, job_run_id, records_config, datamodel_space, datamodel_external_id, datamodel_version)
Build Records API payloads for schema inconsistencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_issues
|
list
|
List of SchemaIssue objects from SHACL validation |
required |
job_run_id
|
str
|
Unique identifier for this validation run |
required |
records_config
|
RecordsConfig
|
Records API configuration |
required |
datamodel_space
|
str
|
Data model space being validated |
required |
datamodel_external_id
|
str
|
Data model external ID |
required |
datamodel_version
|
str
|
Data model version |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of record payloads ready for Records API |
Source code in cognite_data_quality/_records.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
ensure_records_infrastructure(client, records_config)
Ensure Records API stream and container exist.
Source code in cognite_data_quality/_records.py
parse_focus_node_uri(uri, namespace_base='http://purl.org/cognite/')
Parse focusNode URI into (space, external_id), matching NEAT and simple formats.
NEAT: {namespace_base}space/{instance_space}#{urlencoded(external_id)} Simple: {namespace_base}{space}/{external_id}
Source code in cognite_data_quality/_records.py
records_container_properties()
Canonical DataQualityValidationRecord container properties, including 0.5 additives.
Identity fields the product always writes are explicitly nullable=False so greenfield
creates match Toolkit-era projects. Optional / additive fields stay nullable.
Source code in cognite_data_quality/_records.py
rule_engine_container_properties()
Canonical RuleEngineResult container properties.
Identity fields always written by the rule-engine path are explicitly non-nullable.