diff --git a/examples/llm-job/expected-receipt.json b/examples/llm-job/expected-receipt.json new file mode 100644 index 0000000..b5b3e71 --- /dev/null +++ b/examples/llm-job/expected-receipt.json @@ -0,0 +1,108 @@ +{ + "manifest": { + "format": "grounded-json/receipt", + "version": 1, + "createdAt": "2026-03-04T00:00:00.000Z", + "receiptHash": "sha256:e8903465aca9a28f2deca2fdd7c1abe71534f8f099fefab8a6ccc76973748028" + }, + "data": { + "company": "Brightpath Analytics", + "employmentType": "full-time", + "location": "Austin, TX", + "salaryMin": 118000, + "signingBonus": 15000, + "title": "Data Platform Engineer" + }, + "sources": [ + { + "id": "source:ed0e0436dbec", + "mediaType": "text/html", + "contentHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "bytes": 1357 + } + ], + "evidence": { + "/company": [ + { + "pointer": "/company", + "quote": "Brightpath Analytics", + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "grounded", + "observedValue": "Brightpath Analytics" + } + ], + "/employmentType": [ + { + "pointer": "/employmentType", + "quote": "full-time", + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "grounded", + "observedValue": "full-time" + } + ], + "/location": [ + { + "pointer": "/location", + "quote": "Austin, TX", + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "grounded", + "observedValue": "Austin, TX" + } + ], + "/salaryMin": [ + { + "pointer": "/salaryMin", + "quote": "118,000", + "transforms": [ + "parse-number" + ], + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "grounded", + "observedValue": 118000 + } + ], + "/signingBonus": [ + { + "pointer": "/signingBonus", + "quote": "signing bonus of 15,000 USD", + "transforms": [ + "parse-number" + ], + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "invalid", + "reason": "Quote was not found at the evidence anchor." + } + ], + "/title": [ + { + "pointer": "/title", + "quote": "Data Platform Engineer", + "sourceId": "source:ed0e0436dbec", + "sourceHash": "sha256:ed0e0436dbece71e058a5b94189fe63c320ca695e828c2622dbf38e0f786a8e1", + "status": "grounded", + "observedValue": "Data Platform Engineer" + } + ] + }, + "issues": [ + { + "code": "quote-not-found", + "pointer": "/signingBonus", + "sourceId": "source:ed0e0436dbec", + "message": "Quote was not found at the evidence anchor." + } + ], + "coverage": { + "grounded": 5, + "total": 6, + "missing": 0, + "ambiguous": 0, + "invalid": 1, + "ratio": 0.8333333333333334 + } +} diff --git a/examples/llm-job/llm-response.json b/examples/llm-job/llm-response.json new file mode 100644 index 0000000..0f75b35 --- /dev/null +++ b/examples/llm-job/llm-response.json @@ -0,0 +1,23 @@ +{ + "_note": "Recorded structured output from an LLM asked to return {value, quote} per field for the posting in page.html. 'signingBonus' is hallucinated: the posting never mentions a signing bonus, so its quote cannot be found in the page.", + "company": { + "quote": "Brightpath Analytics", + "value": "Brightpath Analytics" + }, + "employmentType": { "quote": "full-time", "value": "full-time" }, + "location": { "quote": "Austin, TX", "value": "Austin, TX" }, + "salaryMin": { + "quote": "118,000", + "transforms": ["parse-number"], + "value": 118000 + }, + "signingBonus": { + "quote": "signing bonus of 15,000 USD", + "transforms": ["parse-number"], + "value": 15000 + }, + "title": { + "quote": "Data Platform Engineer", + "value": "Data Platform Engineer" + } +} diff --git a/examples/llm-job/page.html b/examples/llm-job/page.html new file mode 100644 index 0000000..4af8d69 --- /dev/null +++ b/examples/llm-job/page.html @@ -0,0 +1,43 @@ + + + + + Data Platform Engineer — Brightpath Analytics + + +
+

Data Platform Engineer

+

Brightpath Analytics

+

Austin, TX (on site)

+

Posted on March 3, 2026

+
+

About the role

+

+ Brightpath is hiring for this role to build and operate the pipelines + that move product data into our warehouse. +

+

+ This is a full-time position based in our Austin office. The salary + range for this role is 118,000–142,000 USD per year, depending on + experience. +

+
+
+

What you will do

+ +
+
+

Requirements

+ +
+
+ + diff --git a/examples/llm-job/run.mjs b/examples/llm-job/run.mjs new file mode 100644 index 0000000..0d1a0c4 --- /dev/null +++ b/examples/llm-job/run.mjs @@ -0,0 +1,52 @@ +// Ground a recorded LLM extraction against a saved job posting page. +// Run from the repo root after `npm run build:package`: +// node examples/llm-job/run.mjs +// The receipt is compared with expected-receipt.json; the run fails if +// the two differ. The clock is pinned so the receipt is reproducible. +import { readFileSync } from 'node:fs'; +import { ground } from 'grounded-json'; +import { z } from 'zod'; + +const dir = new URL('./', import.meta.url); +const page = readFileSync(new URL('page.html', dir), 'utf8'); +const { _note, ...fields } = JSON.parse( + readFileSync(new URL('llm-response.json', dir), 'utf8'), +); + +// Prompt pattern: "For every field return { value, quote } where quote is copied verbatim from the source." +const data = Object.fromEntries( + Object.entries(fields).map(([k, f]) => [k, f.value]), +); +const evidence = Object.entries(fields).map(([k, f]) => ({ + pointer: `/${k}`, + quote: f.quote, + ...(f.transforms && { transforms: f.transforms }), +})); + +const receipt = ground({ + data, + sources: [{ mediaType: 'text/html', content: page }], + evidence, + schema: z.object({ + title: z.string(), + company: z.string(), + location: z.string(), + employmentType: z.string(), + salaryMin: z.number(), + signingBonus: z.number(), + }), + options: { now: () => new Date('2026-03-04T00:00:00.000Z') }, +}); + +console.log('coverage:', receipt.coverage); +for (const issue of receipt.issues) + console.log(`REJECT ${issue.pointer}: ${issue.code}`); + +const expected = JSON.parse( + readFileSync(new URL('expected-receipt.json', dir), 'utf8'), +); +if (JSON.stringify(receipt) !== JSON.stringify(expected)) { + console.error('FAIL receipt differs from expected-receipt.json'); + process.exit(1); +} +console.log('PASS receipt matches expected-receipt.json');