Analysis Schema Reference

Complete YAML schema for analysis definitions

Analysis definitions live in analysis.d/*.yaml and define scheduled AI analysis jobs that run against ingested data. They share the same AI operation format as source definitions but add scheduling and data query configuration.

schema_version: 1
name: anomaly_detection
display_name: "Anomaly Detection"
enabled: true

schedule:
  interval: "5m"

data:
  lookback: "1h"
  min_records: 10
  max_records: 500
  layers:
    - flights_commercial
    - ships

ai:
  enabled: true
  operations:
    - name: detect_anomalies
      prompt: >
        Analyze the following {{ .RecordCount }} records from the last {{ .Lookback }}...
      output_schema:
        type: object
        properties:
          anomalies:
            type: array
      max_tokens: 2048
      temperature: 0.0

Top-level

schema_version integer
Schema version number.
name string required
Unique analysis definition name. Used as the key in the definition registry and in schema registry keys.
display_name string
Human-readable name for display in the UI.
enabled boolean default: false
Whether this analysis job is active. When false, the definition is loaded but the scheduler does not run it.

Schedule

Defines when the analysis job runs. Exactly one of interval or cron must be set.

schedule.interval string
Go duration string defining the run frequency (e.g., "5m", "1h", "30s"). Mutually exclusive with cron.
schedule.cron string
Cron expression defining the run schedule (e.g., "*/5 * * * *" for every 5 minutes). Mutually exclusive with interval.
Mutually exclusive
You must set exactly one of interval or cron. Setting both or neither causes a validation error.

Data

Defines what data to fetch for analysis. The engine queries the database for entity+observation records matching these criteria and passes them to the AI prompt template.

data.lookback string required
Time window for data queries as a Go duration string (e.g., "1h", "24h"). Only records with timestamps within this window from the current time are included.
data.min_records integer default: 0
Minimum number of records required before the analysis runs. If fewer records are available, the job is skipped for that cycle.
data.max_records integer default: 500
Cap on the number of records sent to the LLM prompt. When 0, the default of 500 is used.
data.layers string[]
Layer types to query. When empty, records from all layers are included.
data.filter string
CEL expression for pre-filtering records before they are sent to the LLM. The expression has access to entity and observation map variables.
data.sql string
Raw SQL query for advanced data retrieval. Validated read-only at run time – on each execution the engine calls aiquery.ValidateReadOnlySQL (in fetchDataFromSQL) and aborts the run if the query is not read-only. It is not checked at load time, and a definition that sets data.sql fails its run if no query executor is configured.

Dedup

Optional deduplication configuration. When set, records that already have recent insights (within the window) are filtered out before calling the LLM, preventing duplicate analysis.

data.dedup.window string required
Go duration string defining the dedup window (e.g., "2h"). Records with existing insights newer than this are excluded.
data.dedup.key_fields string[] required
Fields used as the composite dedup key. Min length: 1.

AI Operations

The ai section uses the same SourceAIConfig structure as source definitions. See the Source Schema Reference for the full field reference on ai.enabled and ai.operations[].

Output Noise Control and Cross-Layer Refs

Two operations[].output fields are specific to analysis insight storage and are not covered by the source-schema delegation above.

operations[].output.min_attention string
Minimum attention level a result must carry to be stored and pushed. One of info, low, medium, high, critical (validator oneof). Results below this floor – including absent or unclassified attention, treated as info – are dropped. When results_path resolves to an empty array, the all-clear summary insight is suppressed if a floor is configured. When unset, the engine-wide ai.min_attention default applies (community default: low).
operations[].output.ref_fields object[]

Cross-layer entity references. Each entry maps a field in the LLM result item (whose value is an external_id) to an entity in another layer, creating an extra ai_insight_refs row. Both keys are required per entry:

  • field (string, required) – result-item property holding the external ID
  • layer_type (string, required) – layer to scope the external_id lookup
output:
  results_path: "assessments"
  ref_fields:
    - field: "conflict_external_id"
      layer_type: "conflict_events"

Prompt Template Variables

Analysis operation prompts receive an AnalysisPromptData context with these variables:

VariableTypeDescription
.RecordCountintTotal number of records in the query result
.LookbackstringThe lookback duration string
.Records[]AnalysisRecordArray of entity+observation records
.LayerCountintNumber of distinct layer types in the results
.LayerStats[]LayerStatPer-layer statistics
.OutputSchemastringThe JSON schema string for structured output

Each AnalysisRecord contains:

FieldTypeDescription
EntityIDstringInternal entity ID
EntityNamestringHuman-readable entity name
ExternalIDstringExternal ID from the source
LayerTypestringLayer type this record belongs to
Latfloat64Latitude
Lonfloat64Longitude
Altitudefloat64Altitude in meters
Metadatamap[string]stringMerged entity + observation metadata
EntityMetadatamap[string]stringEntity-only metadata
ObsMetadatamap[string]stringObservation-only metadata
TimestampstringObservation timestamp

CEL Filter Environment

Analysis CEL filters use a different environment from source filters. The available variables are:

VariableTypeDescription
entitymap[string]dynEntity fields including metadata
observationmap[string]dynObservation fields including metadata

The string extension library is available. Math and time custom functions from source CEL are not available in analysis filters.

Edit this page on GitHub