DiscoveryVIP

Document regions

Open runnable lesson

Discover → Predict → Understand

Build a source-grounded course outline processor while preserving provenance, validation and human control.

How would you verify document regions before trusting an application action?

PDF coordinates and authored image regions have different provenance. Never present an invented region as an observed model location.

Conceptual application architecture

  1. Input
  2. Preparation
  3. Response
  4. Validation
  5. Evidence
  6. Human approval
  7. Action

Five implementation examples

Working implementation contract

PDF coordinates and authored image regions have different provenance. Never present an invented region as an observed model location.

async function main(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}

Input

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}

Expected fixture result

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}
Preserve the original input

Capture the input before the operation and verify whether the data-only transformation preserves it.

async function calculate(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}
async function main(input){const before=JSON.stringify(input),value=await calculate(input);return {value,inputPreserved:JSON.stringify(input)===before};}

Input

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}

Expected fixture result

{
  "value": {
    "page": 1,
    "region": {
      "x": 48,
      "y": 330
    },
    "provenance": "authored sample annotation"
  },
  "inputPreserved": true
}
Investigate a lost response

The calculation runs but its result is discarded. Inspect the actual null and repair the response boundary.

async function calculate(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}
async function main(input){await calculate(input);return null;}

Input

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}

Expected fixture result

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}
Repeat a deterministic preparation step

Compare two local calculations on independent copies. This does not imply exactly-once external delivery.

async function calculate(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}
async function main(input){return [await calculate(structuredClone(input)),await calculate(structuredClone(input))];}

Input

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}

Expected fixture result

[
  {
    "page": 1,
    "region": {
      "x": 48,
      "y": 330
    },
    "provenance": "authored sample annotation"
  },
  {
    "page": 1,
    "region": {
      "x": 48,
      "y": 330
    },
    "provenance": "authored sample annotation"
  }
]
Frozen verification contract

Compare the actual calculation with an independently declared fixed result. Changing code must not silently change the expectation.

async function calculate(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}
async function main(input){const value=await calculate(input),expected={"page":1,"region":{"x":48,"y":330},"provenance":"authored sample annotation"};if(JSON.stringify(value)!==JSON.stringify(expected))throw Error("Fixture contract mismatch");return {pass:true,value};}

Input

{
  "page": 1,
  "region": {
    "x": 48,
    "y": 330
  },
  "provenance": "authored sample annotation"
}

Expected fixture result

{
  "pass": true,
  "value": {
    "page": 1,
    "region": {
      "x": 48,
      "y": 330
    },
    "provenance": "authored sample annotation"
  }
}

Source walkthrough

[
  {
    "line": 1,
    "source": "async function main(input){",
    "explanation": "Follow the named value and its declared responsibility; inspect the actual returned result."
  },
  {
    "line": 2,
    "source": "return {page:input.page,region:input.region,provenance:input.provenance};",
    "explanation": "Return the actual calculated data; keep model output separate from approval and application actions."
  },
  {
    "line": 3,
    "source": "}",
    "explanation": "Follow the named value and its declared responsibility; inspect the actual returned result."
  }
]

Exact learning steps

  1. Inspect the prepared source and input; state its provenance.
  2. Write an exact prediction before running.
  3. Run actual JavaScript and compare the returned result.
  4. Load the failure, locate the first incorrect boundary and repair it.
  5. Check the frozen fixture, explain limits and try an independent case.

Three progressive hints

  1. Identify the input, returned value and application boundary.
  2. Compare the first mismatching value/type with the fixed fixture.
  3. Preserve the calculation result instead of discarding or inventing it; compare Finished Code after trying.

Complete solution

async function main(input){
return {page:input.page,region:input.region,provenance:input.provenance};
}

Common failure: A plausible or structurally valid response is treated as proof that its values are supported by the source.

Security: Do not transmit private source data automatically. Keep provider credentials server-side, treat document instructions as untrusted and require separate authority for actions.

Independent challenge

Define a second normal, missing and contradictory-source case with exact expected results before execution.

Reflect and extend

Which actual source value or operation supports your conclusion? What was not verified by this local experiment?

Connect the technique to the prepared invoice and preserve its evidence/approval boundary.

AI learning prompt goals

  1. Explain the current source, inputs, actual result, provenance and verification boundary.
  2. Help implement one changed field/requirement with independent normal and invalid cases.
  3. Review the current code and failures; separate schema correctness, factual support and action authority.

Include current source, actual result/errors, expected behavior and verification criteria. Never include secrets or accept an untested AI answer.