Software architecture · 3 min read

Cognitive Primitives: Stop Building Everything as a Prompt

An extraction contract gives the caller a way to check where each value came from.

Worked example. Source note — API v2 serves the queue at /jobs. Returned value — /jobs. Source slice [27, 32) — /jobs.

A documenter receives a release note and a two-field assignment. Find the endpoint and the API version. The note says “API v2 serves the queue at /jobs.” The first answer looks excellent until you try to use it. The worker has returned /v2/jobs, a plausible path assembled from two pieces of the sentence. A JSON parser will accept it. A reader copying the path will call a different endpoint.

This is the smallest example I use to explain a cognitive primitive. Give a recurring operation a name that describes what the caller can expect. For EXTRACT, a returned value must be traceable to an identified source. A caller can change the prompt, model, or runtime and keep that expectation.

Give the worker something it can decline

I would start with three possible outcomes for each field. A directly supported value carries its evidence. A missing value stays missing. Two incompatible values produce a conflict with both references attached. Without that third state, a model can satisfy a requirement to fill every field by silently choosing whichever mention appears later in the document.

result = extract(
    source=document,
    fields=["endpoint", "version"],
    require_evidence=True,
    timeout=10,
)
validate(result, ExtractionSchema)

That interface is a design sketch. In a concrete implementation the caller also needs a source revision and an agreed coordinate system for spans. A byte offset into a UTF-8 file and a character offset into decoded text can point to different places. Pick one, record it with the document identifier, and use it in the verifier.

Run the cheapest independent check

Take the exact sentence above as a fixture and ask for the endpoint. Slice the source at the reported span. Compare the slice with the value. A result of /v2/jobs fails immediately. A result of /jobs accompanied by the exact quote passes this check. Now move the same word into a sentence about a retired endpoint. The equality check still passes. To test meaning, add a fixture that asks specifically for the current endpoint and expect the retired one to be excluded.

I would keep normalization as a separate step. Stripping a trailing slash or expanding a relative path may be valuable to the next caller. Recording the raw value first lets a reviewer reproduce the transformation and locate which step introduced an error. The same discipline helps with a timeout. Preserve it as an operation-level failure so a scheduler can distinguish an unfinished extraction from a completed search that found nothing.

Try the contract before composing it

The same operation can extract commitments from a meeting note. In that example a bounded cognitive unit specifies the source note, the judgment, the allowed span or uncertainty response, and the deadline. A separate matcher can attach a project without changing the writer’s words. Try the meeting-note workbench

For a small evaluation, freeze three notes and their expected outcomes. Use one with a direct answer, one with the version absent, and one with contradictory rollout instructions. Change the wording around each fact while keeping the expected fields fixed. Record evidence matches and correct abstentions separately. A system that always abstains can have impeccable citations and still do very little work.

For a Fredrin-style documenter, this gives the next worker a bounded handoff. A release writer can quote the observed endpoint, ask an owner to resolve a conflict, or leave a missing version out of a draft. The first primitive earns its place when those decisions can survive a change of model without every downstream prompt having to learn how to read a release note again.

Supporting diagrams (4)
Proposed contract. Direct mention — supported. No mention — missing. Incompatible mentions — conflict.
Three ways a field can resolve
Proposed interface. Input — Document revision + field names. Operation — EXTRACT with a deadline. Output — Value, status and evidence.
The extraction boundary
Worked example. Source — GET /jobs/. Extracted spelling — /jobs/. Downstream canonical form — /jobs.
Keep the raw spelling
Worked example. $ extract endpoint version. source   Queue path is /jobs. endpoint /jobs. version  missing.
A fixture for missing evidence
Documenter workspaceExtract a fact with evidence ↗