Tutorial: hold a batch on a failed lab result
This tutorial follows one net quantity check from the lab to the order desk. A lab results export lands in a watched folder, a pipeline turns it into QA test objects linked to production batches, and an automation proposes a hold the moment a tub fill comes in under its declared volume. A person in quality approves the hold, and the production sheet and the order desk record it. Every step shows the command and the output the service returns. Plan on about an hour
place-hold, with conditions and writeback to the production sheet and the order deskIn the platform today
- Everything on this page runs in the platform service, and the outputs shown are what it returns, trimmed to the fields that matter where an ellipsis shows
- The tutorial builds on the ontology folder from the quickstart and adds to the same files: watched folders, object, link and action types and an automation in
ontology.yaml, a pipeline inpipelines.yamland two writeback targets insystems.yaml, as described in Object types, Pipelines, Automations and Writeback
What you will build
The illustrative ice cream maker fills 11.4 L tubs for its scoop shops and wholesale customers on Line 2, at tub filler T-2. The lab weighs a 24-tub sample at the filler and records the net contents in its LIMS, which exports results as CSV files. Today, the QA manager reads those files, notices a failure, phones the planner and types a hold into the production sheet and the order desk
By the end of this tutorial, the same failure produces a proposed hold for each batch the sample covers, with the measurement and the declared volume in its reason, and approving it records the hold on the production sheet, blocks the stock at the order desk and leaves a complete record
The example result is QA-7710: a net quantity check at T-2 on a sample from batch B-0841, measured at 11.18 L against 11.4 L declared. The same sample covers B-0842, filled at T-2 straight after
- The ontology folder from the quickstart on your test service, with
MSO_API_URLandMSO_TOKENset as there - The quickstart's administrator, who reloads the ontology, runs pipelines and evaluates automations. This tutorial also gives them the
QUALITYaccess label, andoperationslets them approve the hold - No production systems. The production sheet and the order desk are raw tables that stand in for them
Both writeback targets here are raw tables that stand in for the systems. To call a system's own API instead, give the operation kind: http, with its address, typed inputs and an undo call, as described in Writeback
1. Connect the lab results export
Add the QUALITY access label, the QA manager and two watched folders to ontology.yaml: one for the production sheet's batch export and one for the LIMS results export. Both folders carry QUALITY, so only people who hold it can see them or upload to them
# ontology.yaml: replace accessLabels and users
accessLabels:
- { id: INTERNAL, name: Internal }
- { id: QUALITY, name: Quality }
users: # ids as your identity provider signs people in
- { id: ops.lead, name: Operations lead, groups: [admins, operations],
accessLabels: [INTERNAL, QUALITY] }
- { id: dispatch.desk, name: Dispatch desk, groups: [dispatch], accessLabels: [INTERNAL] }
- { id: qa.manager, name: QA manager, groups: [quality], accessLabels: [INTERNAL, QUALITY] }
# ontology.yaml: add under ingest.folders
plant-batches:
table: raw.plant_batches
key: [batch_no]
pattern: ["*.csv"]
allowedGroups: [operations, quality]
accessLabel: QUALITY
lims-export:
table: raw.lims_samples
key: [sample_id]
pattern: ["*.csv"]
allowedGroups: [operations, quality]
accessLabel: QUALITY
Save the production sheet's export as batches.csv and the LIMS's latest results as QA-7709_results.csv
batch_no,product,line,filler,batch_status,qa_status,hold_flag,hold_reason
B-0839,Vanilla bean 11.4 L tub,Line 2,T-2,COMPLETE,RELEASED,N,
B-0840,Island strawberry 11.4 L tub,Line 2,T-2,COMPLETE,PENDING_QA,N,
B-0841,Sea salt caramel 11.4 L tub,Line 2,T-2,COMPLETE,PENDING_QA,N,
B-0842,Maple walnut 11.4 L tub,Line 2,T-2,COMPLETE,PENDING_QA,N,
B-0844,Vanilla bean 11.4 L tub,Line 1,T-1,SCHEDULED,PENDING_QA,N,
sample_id,test_name,sample_point,result_code,result_value,sampled_at,reported_at,batch_refs,equipment_code
QA-7704,Net quantity check,"Tub filler T-2, 24-tub sample from B-0839",PASS,11.47,2026-10-26T10:00:00-03:00,2026-10-26T13:00:00-03:00,B-0839,EQ-FIL2
QA-7706,Fat and solids,"Mix tank 1, B-0840",PASS,15.2,2026-10-27T08:30:00-03:00,2026-10-27T11:00:00-03:00,B-0840,EQ-MIX1
QA-7708,Net quantity check,"Tub filler T-2, 24-tub sample from B-0840",PASS,1146,2026-10-27T10:00:00-03:00,2026-10-27T13:00:00-03:00,B-0840,EQ-FIL2
QA-7709,Net quantity check,"Tub filler T-2, 24-tub sample from B-0840",PASS,11.45,2026-10-27T15:00:00-03:00,2026-10-27T18:00:00-03:00,B-0840,EQ-FIL2
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/plant-batches/files?name=batches.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @batches.csv
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/lims-export/files?name=QA-7709_results.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @QA-7709_results.csv
{"revision":"e554d54d9cc4"}{…,"folder":"plant-batches","table":"raw.plant_batches","status":"succeeded","rows":5,…}{…,"folder":"lims-export","table":"raw.lims_samples","status":"succeeded","rows":4,…}The LIMS file holds four results from earlier in the week. QA-7708 has a typing error: 1146 L where the analyst meant 11.46. A file loads once, by its content, so uploading the same file again is skipped
{…,"status":"skipped","files_skipped":1,"duplicateOf":"QA-7709_results.csv",…}2. Build the backing datasets, with checks
The quality pipeline has three steps
- The first shapes the production sheet's batches
- The second turns the LIMS's result codes into the five results the Ontology uses and splits the list of batches a test covers
- The third makes one row per test and batch, for the Tested batch join, from the second step's result in the same build
Mapping the codes here, instead of passing the LIMS's text through, is what catches a code the LIMS starts sending later: the step maps it to nothing, and the notNull check on result fails the build instead of publishing it
Write the checks with the step, so the very first version of the dataset is gated. They protect the shape of the data, not the spec: net contents of 11.18 L are a real measurement and must reach the Ontology, while 1,146 L is a typing error and must not
checks are shorthand for a key, required columns, allowed values and row counts, and fail the build by default; each expectation is a row predicate whose onFail is warn, drop or fail
# pipelines.yaml: add under pipelines
- id: quality
name: Lab results and batches
owner: Quality
steps:
- output: gold.batches
key: batchNo
inputs: [raw.plant_batches]
sql: |
select batch_no as batchNo, product, line, filler,
case upper(batch_status) when 'SCHEDULED' then 'Scheduled' when 'RUNNING' then 'Running'
else 'Complete' end as status,
case upper(qa_status) when 'ON_HOLD' then 'On hold' when 'RELEASED' then 'Released'
else 'Pending QA' end as qaStatus,
coalesce(hold_flag = 'Y', false) as hold, hold_reason as holdReason
from raw.plant_batches
checks:
- { primaryKey: [batchNo] }
- output: gold.qa_tests
key: testNo
inputs: [raw.lims_samples]
sql: |
select sample_id as testNo, test_name as kind, sample_point as site,
case upper(result_code) when 'PENDING' then 'Pending'
when 'NEG' then 'Negative' when 'POS' then 'Positive'
when 'PASS' then 'Pass' when 'FAIL' then 'Fail' end as result,
result_value as value, cast(sampled_at as timestamptz) as sampled,
cast(reported_at as timestamptz) as resultAt,
equipment_code as equipmentId,
case when coalesce(batch_refs, '') = '' then []::varchar[]
else string_split(batch_refs, ';') end as batches
from raw.lims_samples
checks:
- { primaryKey: [testNo] }
- { notNull: [kind, result] }
expectations:
- name: Net contents plausible
row: "kind <> 'Net quantity check' or value is null or value between 0 and 20"
onFail: drop
- name: Reported result has a value
row: "result = 'Pending' or value is not null"
onFail: warn
- output: gold.tested_batches
key: testBatchId
inputs: [gold.qa_tests]
sql: |
select testNo || '/' || batchNo as testBatchId,
testNo, batchNo, kind, result, value, equipmentId
from (select *, unnest(batches) as batchNo from gold.qa_tests)
checks:
- { primaryKey: [testBatchId] }
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/pipelines/quality:run" \
-H "Authorization: Bearer $MSO_TOKEN"
{"build":{…,"pipeline_id":"quality","status":"succeeded","steps":3,"rows_out":11,"rows_dropped":1,…},…}The dropped row waits in quarantine with the expectation it broke, so someone can correct it and replay it into later builds
curl "$MSO_API_URL/api/v2/quarantine" \
-H "Authorization: Bearer $MSO_TOKEN"
{"data":[{…,"dataset":"gold.qa_tests","expectation":"Net contents plausible","status":"held","rowKey":"QA-7708",…}],…}A row check of 11.4 to 11.6 L on net contents would drop exactly the results this tutorial needs to act on, and the failing batch would never appear. Checks decide whether a row is trustworthy data. Whether a batch is in spec is a business fact, and it belongs on the object, where an action condition and an automation can use it
3. Model the QA test object type
Add three object types and two link types. A foreign key is not enough between tests and batches: one sample can cover several batches, as QA-7710 covers B-0841 and B-0842, and a batch has several tests, so each pair is its own Tested batch object. Tested batch also carries its test's kind, result and value, so the automation in step 5 can watch it directly
# ontology.yaml: add under objectTypes
batch:
name: Production batch
plural: Production batches
description: Production runs on Line 1 and Line 2, with QA status and holds
key: batchNo
title: "{batchNo} · {product}"
backing: gold.batches
accessLabel: QUALITY
properties:
batchNo: { type: string, name: Batch }
product: { type: string }
line: { type: string, values: [Line 1, Line 2] }
filler: { type: string }
status: { type: string, values: [Scheduled, Running, Complete] }
qaStatus: { type: string, name: QA status, values: [Pending QA, On hold, Released] }
hold: { type: boolean, name: On hold }
holdReason: { type: string }
qatest:
name: QA test
plural: QA tests
description: Lab and line results from the LIMS
key: testNo
title: "{testNo} · {kind}"
backing: gold.qa_tests
accessLabel: QUALITY
properties:
testNo: { type: string, name: Test }
kind: { type: string, required: true }
site: { type: string, name: Sample site }
result: { type: string, values: [Pending, Negative, Positive, Pass, Fail] }
value: { type: double }
sampled: { type: timestamp }
resultAt: { type: timestamp, name: Reported }
equipmentId: { type: string, name: Sampled at }
batches: { type: array }
tested-batch:
name: Tested batch
plural: Tested batches
description: A batch a QA test covers
key: testBatchId
title: "{testBatchId}"
backing: gold.tested_batches
accessLabel: QUALITY
properties:
testBatchId: { type: string }
testNo: { type: string, required: true }
batchNo: { type: string, required: true }
kind: { type: string }
result: { type: string }
value: { type: double }
equipmentId: { type: string }
# ontology.yaml: add under linkTypes
tested-batch-test:
{ from: tested-batch, to: qatest, via: testNo, name: Test, reverse: Batches tested }
tested-batch-batch:
{ from: tested-batch, to: batch, via: batchNo, name: Tests batch, reverse: QA tests }
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/refresh" \
-H "Authorization: Bearer $MSO_TOKEN"
mso query batch --where '{"batchNo": "B-0840"}' \
--follow tested-batch-batch --follow tested-batch-test \
--select testNo,kind,result,value
{…,"syncs":[…,{…,"object_type":"batch","rows_upserted":5,"rows_rejected":0,…},{…,"object_type":"qatest","rows_upserted":3,"rows_rejected":0,…},{…,"object_type":"tested-batch","rows_upserted":3,"rows_rejected":0,…}]}_key _title testNo kind result value
------- ---------------------------- ------- ------------------ ------ -----
QA-7706 QA-7706 · Fat and solids QA-7706 Fat and solids Pass 15.2
QA-7709 QA-7709 · Net quantity check QA-7709 Net quantity check Pass 11.45
2 of 2 qatest
B-0840's earlier checks both pass, and QA-7708 is not among them: the dropped row never reached the Ontology. The three types carry QUALITY, so people without it never see them
4. Define the place-hold action
The action changes the batch and nothing else. Its conditions make sure the batch is not already on hold and has been made, and only quality and operations may apply it. The writeback records the hold on the production sheet and blocks the batch's stock at the order desk, which is what stops it being picked for a shop or a wholesale order
# ontology.yaml: add under actionTypes
place-hold:
name: Place QA hold
objectType: batch
description: Stop a batch from shipping until QA releases it
accessLabel: QUALITY
allowedGroups: [quality, operations]
parameters:
batch: { type: object, objectType: batch, required: true }
reason: { type: string, required: true }
conditions:
- name: notHeld
message: "{{batch.batchNo}} is already on hold"
all: [ { left: { parameter: batch, property: hold }, op: isNot, right: true } ]
- name: made
message: "{{batch.batchNo}} has not been made yet"
all: [ { left: { parameter: batch, property: status }, op: isNot, right: Scheduled } ]
rules:
- modify:
object: { parameter: batch }
set: { hold: true, qaStatus: On hold, holdReason: { parameter: reason } }
writeback:
- system: production-sheet
operation: set-hold
payload: { batchNo: { parameter: batch }, reason: { parameter: reason } }
- system: order-desk
operation: block-stock
payload:
batchNo: { parameter: batch }
reason: { parameter: reason }
blockedBy: { currentUser: name }
blockedAt: { now: true }
notify:
- { group: quality, message: "{{batch.batchNo}} on QA hold: {{reason}}" }
Each writeback entry names an operation in systems.yaml. set-hold updates the batch's row in the production sheet's table, where a value starting with = is written as it stands; block-stock adds a row to the order desk's table. Each write is queued in the same commit as the edits and delivered once, with an idempotency key, and a failure is retried
# systems.yaml: add under systems
production-sheet:
name: Production sheet
operations:
set-hold:
table: raw.plant_batches
key: { batch_no: batchNo }
set: { hold_flag: "=Y", qa_status: "=ON_HOLD", hold_reason: reason }
order-desk:
name: Order desk
operations:
block-stock:
table: raw.orderdesk_stock_blocks
insert:
{ batch_no: batchNo, reason: reason, blocked_by: blockedBy, blocked_at: blockedAt }
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
mso actions check place-hold batch=B-0844 reason="QA-7710 underfill"
place-hold: INVALID
condition made: B-0844 has not been made yet
B-0844 is scheduled for tomorrow on Line 1, so the made condition refuses it, with its own message. That is the test you want first: an action that can hold a batch before it is made would let an automation block stock that does not exist
5. Add the automation
The automation watches Tested batch objects. When one enters the set of failed net quantity checks, it proposes place-hold for that batch, as the QA manager, its owner. It never applies the action itself: each proposal waits for a person in quality or operations, and holding product stays a person's decision
# ontology.yaml: add at the end
automations:
- id: hold-on-underfill
name: Propose a hold when a net quantity check fails
owner: qa.manager
trigger:
kind: threshold
objectType: tested-batch
where: { kind: Net quantity check, result: Fail }
effect:
kind: propose
action: place-hold
parameters:
batch: "{{object.batchNo}}"
reason: "Underfill at {{object.equipmentId}}: {{object.value}} L against 11.4 L declared ({{object.testNo}})"
rationale: "{{object.testNo}} failed its net quantity check"
curl -X POST "$MSO_API_URL/api/v2/ontology:reload" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/automations:tick" \
-H "Authorization: Bearer $MSO_TOKEN"
{"data":{"hold-on-underfill":{"status":"active","runs":0}}}The service evaluates automations on a timer, and automations:tick lets an administrator evaluate them now. The first evaluation records which tested batches already match and proposes nothing, so results that failed before the automation existed never raise a hold. From then on it fires when a tested batch enters the set
6. Send a failing result and approve the hold
Put QA-7710 into the export folder the way the LIMS would, run the pipeline and evaluate the automation
sample_id,test_name,sample_point,result_code,result_value,sampled_at,reported_at,batch_refs,equipment_code
QA-7710,Net quantity check,"Tub filler T-2, 24-tub sample from B-0841",FAIL,11.18,2026-10-28T10:00:00-03:00,2026-10-28T12:00:00-03:00,B-0841;B-0842,EQ-FIL2
curl -X POST \
"$MSO_API_URL/api/v2/ingest/folders/lims-export/files?name=QA-7710_results.csv" \
-H "Authorization: Bearer $MSO_TOKEN" --data-binary @QA-7710_results.csv
curl -X POST "$MSO_API_URL/api/v2/pipelines/quality:run" \
-H "Authorization: Bearer $MSO_TOKEN"
curl -X POST "$MSO_API_URL/api/v2/automations:tick" \
-H "Authorization: Bearer $MSO_TOKEN"
mso proposals list --status pending
{…,"folder":"lims-export","table":"raw.lims_samples","status":"succeeded","rows":1,…}{"build":{…,"status":"succeeded","steps":2,"steps_skipped":1,…},…}{"data":{"hold-on-underfill":{"status":"active","runs":2}}}proposal status action object by rationale created
------------------------------- ------- ---------- ------------ ---------------------------- ------------------------------------- ---------------------------
prop_01M62AQP1X9T5FA8MG7X6CXN92 pending place-hold batch B-0842 automation:hold-on-underfill QA-7710 failed its net quantity check 2026-10-28T22:40:16.957029Z
prop_01M62AQP0NM3HQCKCZ79WJXGR1 pending place-hold batch B-0841 automation:hold-on-underfill QA-7710 failed its net quantity check 2026-10-28T22:40:16.917119Z
There is one proposal for each batch the sample covers, with the measurement in its reason. Approve them from the command line as here, from Python with mso.proposals.approve, or in the app
mso proposals approve prop_01M62AQP0NM3HQCKCZ79WJXGR1 \
--note "Re-weigh confirms the underfill"
mso proposals approve prop_01M62AQP1X9T5FA8MG7X6CXN92 \
--note "Re-weigh confirms the underfill"
prop_01M62AQP0NM3HQCKCZ79WJXGR1: approved
prop_01M62AQP1X9T5FA8MG7X6CXN92: approved
Approving runs the action with your permissions and your access labels, and checks its conditions again against current data, so a batch someone held by hand in the meantime is refused with the failing condition. The action log records the automation and the proposal as the origin, and you as the person who decided. Someone outside quality and operations who is not an administrator cannot approve it
7. Confirm the writeback and the action log
Check the result in four places: on the batch, in the action log, on the production sheet and at the order desk
mso get batch B-0841
mso log --type batch
_key B-0841
_type batch
_version 2
_updatedAt 2026-10-28T22:40:17.472954Z
_edited ["hold", "holdReason", "qaStatus"]
_title B-0841 · Sea salt caramel 11.4 L tub
batchNo B-0841
product Sea salt caramel 11.4 L tub
line Line 2
filler T-2
status Complete
qaStatus On hold
hold true
holdReason Underfill at EQ-FIL2: 11.18 L against 11.4 L de…
log when action object by reverts
------------------------------- --------------------------- ---------- ------------ -------- -------
alog_01M62AQPWXTHBTAMAB7X45MEFT 2026-10-28T22:40:17.867600Z place-hold batch B-0842 ops.lead
alog_01M62AQPJ0R6HGKS5WSTT8BWWR 2026-10-28T22:40:17.516791Z place-hold batch B-0841 ops.lead
{"data":[{…,"action":"place-hold","object_key":"B-0841","actor_id":"ops.lead","automation":"automation:hold-on-underfill","proposal_id":"prop_01M62AQP0NM3HQCKCZ79WJXGR1","approved_by":"ops.lead","reason":"Re-weigh confirms the underfill","writeback_status":"delivered",…}]}mso sql "select batch_no, qa_status, hold_flag from raw.plant_batches
where batch_no in ('B-0841', 'B-0842')"
mso sql "select batch_no, reason, blocked_by, blocked_at from raw.orderdesk_stock_blocks
order by batch_no"
batch_no qa_status hold_flag
-------- --------- ---------
B-0841 ON_HOLD Y
B-0842 ON_HOLD Y
2 rows
batch_no reason blocked_by blocked_at
-------- ------------------------------------------------ --------------- ---------------------------
B-0841 Underfill at EQ-FIL2: 11.18 L against 11.4 L de… Operations lead 2026-10-28T22:40:17.509922Z
B-0842 Underfill at EQ-FIL2: 11.18 L against 11.4 L de… Operations lead 2026-10-28T22:40:17.860086Z
2 rows
The action log is also an operational table, so the QA manager can answer "which holds came from the underfill automation, and who approved them" in SQL, with the SQL grants of their role
mso sql "select log_id, object_key as batch, approved_by, writeback_status
from ops.action_log
where action = 'place-hold' and automation = 'automation:hold-on-underfill'
order by object_key"
log_id batch approved_by writeback_status
------------------------------- ------ ----------- ----------------
alog_01M62AQPJ0R6HGKS5WSTT8BWWR B-0841 ops.lead delivered
alog_01M62AQPWXTHBTAMAB7X45MEFT B-0842 ops.lead delivered
2 rows
Until the production sheet agrees, the batch shows the hold as edits in _edited. The next build reads the hold back from the production sheet, and the markers clear. If a system had refused a write, the action log would show the writeback as failed and the write would wait in dead letters for a person
curl -X POST "$MSO_API_URL/api/v2/pipelines/quality:run" \
-H "Authorization: Bearer $MSO_TOKEN"
mso get batch B-0841
{…,"syncs":[{…,"object_type":"batch","status":"succeeded","rows_upserted":2,"edits_cleared":6,…},…]}_edited []Clean up
Undo the two holds and pause the automation. Undoing an action reverts its edits and queues the inverse writeback, so the production sheet and the order desk are put back too
mso undo alog_01M62AQPJ0R6HGKS5WSTT8BWWR --reason "Tutorial clean-up"
mso undo alog_01M62AQPWXTHBTAMAB7X45MEFT --reason "Tutorial clean-up"
curl -X POST "$MSO_API_URL/api/v2/automations/hold-on-underfill:pause" \
-H "Authorization: Bearer $MSO_TOKEN"
mso sql "select count(*) as blocks from raw.orderdesk_stock_blocks"
alog_01M62AQPJ0R6HGKS5WSTT8BWWR: REVERTED log alog_01M62AQS64DYVCNRPCR583MW0Y
alog_01M62AQPWXTHBTAMAB7X45MEFT: REVERTED log alog_01M62AQRT4DX76SMYJ3ZKS8T4G
{"id":"hold-on-underfill",…,"status":"paused","paused":true,…}blocks
------
0
1 rows
To remove the tutorial's definitions, take them out of the folder and reload. The raw and backing tables stay in the lakehouse
Next steps
- Add a second automation on
Fat and solidsresults, with its own reason, using the same action - Add a
release-batchaction that clears the hold, with a condition that calls a function infunctions.pyto look for a passing re-weigh at the same filler - Send the hold to the people on shift with a
notifyentry that works its recipients out from the batch - Run the go-live checklist for the folders, the pipeline, the writeback targets and the automation before you point them at production