Beta. STARCO Dev works with synthetic data only: do not send real personal or health data. Every feature shows its real status (Available Beta Beta · in development Coming).

Documentation menu

Tutorial 03

Measures and validation.

Goal: record how many glasses of water a synthetic person drank with the catalogue's hydration_glasses kind, send mistakes on purpose to see validation at work, and read the result in the layer.

time 15 minlevel intermediateuses catalogue Beta · observations Beta · layer read Beta · layer schemas Betatabs curl · Python · TypeScript · CLI (the SDK and the command line are not published as packages yet)
Two ways to have measures.Steps 1 to 4 use the kinds of the STARCO catalogue, each with its own unit, bounds and integer rule. Step 5 defines your own in a layer schema (Beta, v1.1); chapters 11 and 12 of the Academy let you try both, simulated.
  1. 1Kind
  2. 2Send
  3. 3Reject
  4. 4Read
  5. 5Your own

STEP 1 Find the kind and its rules Beta#

Every kind carries the contract each observation is checked against: its layer, one unit, the accepted bounds and whether it must be a whole number.

curl -s "$API/templates" -H "Authorization: Bearer $STARCO_KEY" | jq '.kinds[] | select(.kind == "hydration_glasses")'
Expected outputillustrative · synthetic
{ "kind": "hydration_glasses", "layer": "wellness", "unit": "glasses",
  "accepted_min": 0, "accepted_max": 20, "integer": true }
RuleValueWhy
layerwellnessThe twin must have this layer, or the line is refused with layer_not_enabled_on_twin.
unitglassesOne unit per kind, written exactly so. A line in another unit is rejected, never converted.
integertrueWhole glasses only.
bounds0 to 20Catches typing errors. The bounds check that a value is recordable; they say nothing about the person.

STEP 2 Send valid observations Beta#

One observation per day: the glasses drunk that day, recorded in the evening.

curl -X POST "$API/twins/$TWIN/observations" -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" -d '{
  "observations": [
    {"kind": "hydration_glasses", "value": 6, "unit": "glasses", "observed_at": "2026-11-16T21:30:00Z"},
    {"kind": "hydration_glasses", "value": 8, "unit": "glasses", "observed_at": "2026-11-17T21:30:00Z"},
    {"kind": "hydration_glasses", "value": 7, "unit": "glasses", "observed_at": "2026-11-18T21:30:00Z"} ] }'
Expected outputillustrative · synthetic
200 { "batch_id": "7e0b2a91-…", "accepted": 3, "rejected": [], "recomputed_layers": ["wellness"] }

STEP 3 Watch validation work Beta#

Now send five mistakes on purpose: millilitres instead of glasses, half a glass, a value far above the bound, a kind that does not exist and an extra field.

curl -X POST "$API/twins/$TWIN/observations" -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" -d '{
  "observations": [
    {"kind": "hydration_glasses", "value": 250, "unit": "mL",      "observed_at": "2026-11-15T21:30:00Z"},
    {"kind": "hydration_glasses", "value": 1.5, "unit": "glasses", "observed_at": "2026-11-14T21:30:00Z"},
    {"kind": "hydration_glasses", "value": 25,  "unit": "glasses", "observed_at": "2026-11-13T21:30:00Z"},
    {"kind": "water_ml",          "value": 250, "unit": "mL",      "observed_at": "2026-11-13T21:30:00Z"},
    {"kind": "hydration_glasses", "value": 5,   "unit": "glasses", "observed_at": "2026-11-12T21:30:00Z", "note": "after the gym"} ] }'
Expected outputillustrative · synthetic
422
0 unit_mismatch unit glasses
1 value_not_an_integer value None
2 value_out_of_accepted_bounds value [0, 20]
3 unknown_kind kind None
4 unknown_field note None

The answer is 422 because no line was accepted; its body has the same shape as a 200, with "accepted": 0 and "recomputed_layers": []. No rejected line is stored, partly or otherwise, and the layer is not recomputed. A field named like an identifier, such as email, would be refused as identifier_field_not_accepted. The full list of reasons is in Concepts.

STEP 4 Read it in the layer Beta#

curl -s "$API/twins/$TWIN/layers/wellness" -H "Authorization: Bearer $STARCO_KEY" \
  | jq '.kinds[] | select(.kind == "hydration_glasses")'
Expected outputillustrative · synthetic
{ "kind": "hydration_glasses", "unit": "glasses", "count": 3,
  "latest": { "value": 7, "observed_at": "2026-11-18T21:30:00Z" },
  "min": 6, "max": 8, "mean": 7, "mean_last_7_days": 7,
  "first_observed_at": "2026-11-16T21:30:00Z", "last_observed_at": "2026-11-18T21:30:00Z" }

STEP 5 Your own measures Beta#

A layer schema defines a custom layer with the measures the catalogue does not have, with the same rules you met in step 1: a name, a type, one unit and accepted bounds. Its numeric measures take observations and are validated exactly like the catalogue's kinds, with the same reason codes; a derived measure is calculated from others of its layer.

SCHEMA=$(curl -s -X POST "$API/schemas" -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" -d '{
  "layer": "study",
  "measures": [
    {"name": "water_ml", "type": "integer", "unit": "ml", "min": 0, "max": 10000},
    {"name": "weight_kg", "type": "number", "unit": "kg", "min": 1, "max": 400},
    {"name": "ml_per_kg", "type": "number", "unit": "ml/kg", "expression": "round(water_ml / weight_kg, 1)"}
  ]}' | jq -r .schema.id)
TWIN2=$(curl -s -X POST "$API/twins" -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" \
  -d '{"template": "food_hydration", "layers": ["wellness"], "schemas": ["'$SCHEMA'"]}' | jq -r .twin.id)
curl -s -X POST "$API/twins/$TWIN2/observations" -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" \
  -d '{"observations": [{"kind": "study.water_ml", "value": 1750, "unit": "ml", "observed_at": "2026-11-18T20:00:00Z"}]}'

A custom measure's observation kind is its full name (study.water_ml). A value with no kind on the twin is still refused with unknown_kind, never stored under another name.

What just happened

You sent three days of a catalogue kind, and the validator used its unit, integer rule and bounds to accept them and to reject five mistakes, each with a stable reason. The layer shows the numbers: 3 observations, from 6 to 8 glasses, a mean of 7. STARCO shows the numbers; it does not say whether they are enough.

wellnesshydration_glasses validatorglasses · int · 0–20 7 glasses ✓250 mL ✗25 glasses ✗

Next steps#