Skip to main content

Application Context

Application context is an optional but strongly recommended configuration layer that gives the LLM domain knowledge before any tasks are compiled. It affects the accuracy of all task definitions and calibration recommendations.


POST /context

Create or update application context. Creates a new immutable version and deactivates the previous one atomically. Takes effect immediately.

Request Schema

FieldTypeRequiredDescription
domain.descriptionstringYesNatural language description of what the application does and what domain it operates in
domain.entitiesarrayNoList of entity declarations. Each has name (string) and description (string)
domain.decisionsarrayNoList of decision type names (e.g. churn_risk, fraud_alert)
behavioural.data_cadenceenumNobatch | streaming | mixed. Default: batch
behavioural.meaningful_windowsobjectNomin and max duration strings (e.g. 30d, 90d). Informs calibration window clamping
behavioural.regulatoryarrayNoRegulatory frameworks in scope (e.g. GDPR, SOC2, HIPAA)
semantic_hintsarrayNoDomain-specific term definitions. Each has term (string) and definition (string)
calibration_bias.false_negative_costenumNohigh | medium | low
calibration_bias.false_positive_costenumNohigh | medium | low

bias_direction is auto-derived and cannot be set manually: false_negative_cost > false_positive_costrecall. Reverse → precision. Equal → balanced.

Example Request

{
"domain": {
"description": "B2B SaaS churn detection for mid-market software companies.",
"entities": [
{ "name": "account", "description": "company-level subscription" },
{ "name": "user", "description": "individual platform user" }
],
"decisions": ["churn_risk", "expansion_opportunity"]
},
"behavioural": {
"data_cadence": "batch",
"meaningful_windows": { "min": "30d", "max": "90d" },
"regulatory": ["GDPR", "SOC2"]
},
"semantic_hints": [
{ "term": "active user", "definition": "logged in AND performed core action in last 14 days" },
{ "term": "high value account", "definition": "ARR above $50,000" }
],
"calibration_bias": {
"false_negative_cost": "high",
"false_positive_cost": "medium"
}
}

Response Schema — ApplicationContext

FieldTypeDescription
context_idstring (UUID)Auto-generated unique identifier
versionstringAuto-assigned: v1, v2, v3...
domainobjectThe domain context as submitted
behaviouralobjectThe behavioural context as submitted
semantic_hintsarrayThe semantic hints as submitted
calibration_biasobject | nullThe calibration bias including auto-derived bias_direction
created_atdatetimeISO 8601 UTC timestamp
is_activebooleantrue if this is the currently active version

Response Codes

CodeDescription
201Context created. New version active immediately.
400Invalid request — missing required fields or invalid enum values
401Unauthorised — invalid or missing API key

GET /context

Get the currently active context version.

note

When no context has been defined, returns HTTP 404:

  • error.type: not_found
  • Message: "No active application context exists."

This is expected behaviour — not an error. It means context has not been configured yet.

Response Codes

CodeDescription
200Active context returned
404No active context defined

GET /context/versions

List all context versions, newest first.

Response: Array of ApplicationContext objects ordered by created_at descending.


GET /context/versions/{version}

Get a specific context version by version string.

ParameterTypeDescription
versionstringVersion string — e.g. v1, v2, v3

Response Codes

CodeDescription
200Context version returned
404Version not found

GET /context/impact

Shows how many tasks were compiled under older context versions.

Response Schema

FieldTypeDescription
current_versionstringThe currently active context version
tasks_on_current_versionintTasks compiled under the current version
tasks_on_older_versionsarrayList of { version, task_count } for each older version
total_stale_tasksintTotal tasks not on the current context version

Effect on Task Creation

When context is active, the POST /tasks response includes:

FieldTypeDescription
context_versionstring | nullContext version active at task creation. null if no context defined.
context_warningstring | null"No active application context exists..." if no context was defined. null if context was present.

Effect on Calibration

When calibration_bias is defined, POST /conditions/calibrate returns additional fields:

FieldTypeDescription
statistically_optimalfloatRaw optimal value from feedback data alone
context_adjustedfloat | nullBias-adjusted value after applying calibration_bias. null if no bias defined.
recommendedfloatFinal recommended value — equals context_adjusted if bias was applied
adjustment_explanationstring | nullHuman-readable explanation of any adjustment