Search and contents

Instruction claim drafting

A Node can read the documents it takes in and draft instruction claims from them: a quoted sentence together with the quantity it states (a target, a tolerance, a minimum, a maximum or a range, with its unit) and the place in the document it came from. Each claim is a candidate for a person to confirm. Drafting decides nothing about whether a sentence is a requirement, and acts on no claim, confirmed or not.

It is off until a document type asks for it. A type with no draft_claims is ingested for retrieval as it always was and is not read for claims.

Turning it on

Set draft_claims on a document type in the document_types section (see the chunking registry):

{
  "document_types": {
    "work_instruction": {
      "draft_claims": true,
      "strategy": {"name": "heading_sections", "heading_depth": 3, "min_chars": 100, "max_chars": 1200}
    }
  }
}

A site entry of a starter type's name replaces the starter entry whole, so restate its strategy and context as well. The type's strategy must put a locator in every chunk it makes, because a claim points at its place in the document by that locator and not by a chunk number, which changes when the document is cut differently. heading_sections and boundary_rules do. fixed_window and paragraph do not, and a type that declares draft_claims under either is refused when the configuration loads, in the Node and in the offline check. A strategy of your own opts in with stamps_locator=True.

The Node needs the inference section for this, as it does for ingestion, because claims are submitted to the sign-off store and the optional naming step calls the model. draft_claims does not change a type's fingerprint, so setting it does not make older chunks look stale.

What is found

The program reads the document's text, never the model. In each sentence it finds a number written with a unit, in one of these forms:

FormExamplesFields filled
value 40 Nm target
plus_minus 180 ± 5 °C, 25 mm +/- 0.1, 40 Nm ± 5% target, tolerance, tolerance_unit, and lower and upper worked out exactly
minimum min 38 N, at least 6.5 bar, >= 38 N, 38 N minimum lower
maximum max. 80 °C, do not exceed 80 °C, 80 °C or less upper
range 150-160 °C, 150 to 160 °C, between 150 and 160 °C lower, upper

A number with no unit is not a candidate, which leaves out most part numbers, dates and step numbers. The units are a fixed list (temperature, length, mass, torque, force, pressure, speed, time, electrical, volume and %); in and A are left out because they are also ordinary words. A unit is reported in one spelling whichever way the document wrote it (Nm, N·m and N-m are all N·m).

A rate is read whole or not at all: 3 °C/min and 2 L/s are units of their own, and a number followed by / and a word that is not a listed rate (3 widgets/h) is skipped, because 3 °C would misstate 3 °C/min. A form the sentence began and the reading refused (a tolerance whose units disagree, a range written backwards, 45 ± 10 % RH with no unit on the target) yields no candidate and no plain value from inside it. and joins a range only after between, so at 0, 50 and 100 mm is not the range 50 to 100.

The same text always gives the same candidates in the same order. The quoted sentence is an exact slice of the document, never edited. Sentences end at a full stop, a blank line, a list item or a table row, and not after an abbreviation such as max. before a number.

At most 200 candidates are drafted from one revision of one document, in document order, so a long specification cannot bury a reviewer. The Activity Log entry says how many were left out (candidates_over_limit).

The model's part

With inference enabled, the model is shown each candidate's sentence and the quantity read from it, 20 at a time. For each, it answers two things:

  1. Whether the sentence states a requirement people must meet. A part number or a date does not. A candidate it says is not a requirement is not submitted.
  2. What the quantity is called, in the sentence's own words. A name is kept only if its words are in the sentence and it does not repeat a number the quantity carries (within 5 s of printing says when, not what). Otherwise the claim has no name, and the Activity Log entry counts the name as rejected.

The model never writes a field. The quoted sentence, the target, the tolerance, the bounds and the unit are the program's, whatever the model answers.

If the model fails:

  • An answer that is not the asked-for shape is asked for again.
  • If the model never answers usably, the document's claims are drafted without names. The record says drafted_by: fallback and the Activity Log entry carries naming_failed: true. An outage therefore costs the names and the model's discarding of non-requirements, and the document is not embedded again to retry.
  • Claims drafted that way stay as they are. They are not named later.

Hostile text. Text in a document that addresses the model is shown to it as a quoted string among the candidates. At worst it can make the model discard a candidate.

With inference disabled, the candidates are submitted without a name, and the record says drafted_by: fallback. An item the ingestion stage holds for that reason is drafted all the same, because the claims are the program's own.

What lands

Each candidate is a Pending sign-off record of type instruction_claim, submitted by ai-draft:

FieldMeaning
quoted_sentence The sentence, exactly as in the document.
parameter_name What the quantity is called, from the model, or null.
kind, unit, target, tolerance, tolerance_unit, lower, upper The quantity. Numbers are text, so 180.0 stays 180.0. tolerance_unit is the unit or %.
matched_text The words of the sentence the quantity was read from.
locator The place in the document (a heading path, or a step label).
source_document_id, stored_document_id, document_type, document_title, document_number The document. stored_document_id is id@revision_label for a type that keeps each revision.
revision_label, source_revised_at The revision.
drafted_by model or fallback.

Approving a claim changes its status and nothing else: it records that a person confirmed the claim. The review page shows the quoted sentence beside the fields. Editing a claim on the page edits its content like any other record's; the quoted sentence is then whatever the reviewer left there.

The one thing that reads a confirmed claim is an instruction binding, which names it in a Node's configuration and is checked against it. python3 -m engine.instruction_binding_tools --config node.json claims lists the confirmed claims that are still current.

The Activity Log entry

Each run that changes anything writes one Activity Log entry, with trigger instruction_claim_drafting, before it changes anything. It holds:

  • the document and revision, and the provider;
  • drafted_by;
  • the counts: candidates, claims_submitted, claims_already_drafted, claims_discarded, claims_superseded, and names_rejected, candidates_over_limit or naming_failed when not zero.

It never holds text.

  • A later run of the same revision that changes something else (a re-read flagged overwrite, after a configuration change) writes an entry of its own. A retry of the same run writes one.
  • If the entry cannot be written, nothing has changed and the item is offered again.
  • A run that finds nothing new writes nothing, so an item offered on every poll does not fill the log.
  • The entries are document activity: shift_handoff.exclude_document_ingestion leaves them out of a handoff, with the ingestion entries.

Drafted once

A candidate is identified by its revision, its place, its sentence and its quantity (a sentence that appears twice in one place is numbered). The Node keeps one row for each in the table instruction_claim_drafts, written in the same transaction as the sign-off record, so a candidate has both or neither.

  • An item offered again submits nothing and calls the model for nothing. That covers the same revision from the same provider, from two providers, held because inference is disabled and met on every poll, or flagged overwrite.
  • A revision that already has candidates recorded is not read again at all, which keeps a held item from costing a scan on every poll. One flagged overwrite is read again.
  • An overwrite of the same revision with corrected text drafts what is new and supersedes the claims the new text no longer yields, as an older revision's would be.
  • A candidate the model said was not a requirement is recorded too and is not asked about again. To have it reconsidered, supply a new revision.

When chunking changes. A claim a person approved or rejected, or the model discarded, is also recognised by its sentence and quantity alone. If the same revision is read again after the type's chunking changed (a reingest, so the locators moved), the claim is not drafted a second time under its new place. Claims still Pending are withdrawn and drafted again with the new locator, as an edited text's would be.

Revisions

  • replace (the default): a new revision drafts its own claims and supersedes those of every earlier revision of the document. A claim still Pending is moved to Rejected-Superseded, recorded as resolved by instruction-claim-drafting, with no successor; if a person had edited and resubmitted it, the Pending edit is superseded too. A claim already approved or rejected cannot change, so it is marked superseded in instruction_claim_drafts only. A revision older than one already drafted, which arrives late, supersedes nothing.
  • keep: each revision's claims stay as they are, pinned to the revision (stored_document_id is id@label). An item with no revision label is not drafted, and a warning is logged.

Limits

  • Deactivating a document does not withdraw its claims.
  • The Activity Log entry states what the run set out to do, written before it did it. If another writer recorded some of the same candidates at the same moment, or a run died and was finished by the next offer, the counts in the entry can differ from what each run changed; the sign-off records and the instruction_claim_drafts table are what is exact.
  • Only the first 200 candidates of a revision are drafted, in document order, so the claims of a very long document are those of its first sections. The entry says how many were left out.
  • A sentence that no chunk holds whole and whose quantity no chunk holds is given the locator of the sentence before it. Because the locator is part of a candidate's identity, a corrected re-offer of the revision, which supersedes the claims it no longer yields, is how a changed locator is put right.
  • A sentence that names a quantity in another cell of a table (a nominal in one column and its tolerance in the next) is read one cell at a time.
  • A sentence cut through by a chunk window still gets a locator, but only from the quantity's place; a claim's locator names the chunk that holds the sentence, and a joined short section is cited under the first section's locator.
  • The unit list, the form list and the limit of 200 are fixed in the code and have no configuration key.

Release: v0.11.0