Independent reference implementation

Before the answer,
check the boundary.

Which product? Which source? Which route? Inspect the decisions that should happen before a product assistant releases an answer.

Entirely synthetic catalogs and evidence. This is not GolfJoy source, customer data, live model intelligence, or the private evaluation sets discussed in the article.

01 / Choose a boundary

The failure is part of the interface.

Each preset has an independently written expected route. Change its inputs and inspect the result.

Reproduce this boundary

A grounded fact

Original preset · Inputs match the named preset.

Open preset link ↗

Links and reloads open the named preset. Back / Forward also restores edits while this page stays open. Edits live only in tab memory; download JSON to keep them locally. The JSON includes your question, actual decision and source reasons. Synthetic reference data; no live model.

02 / Real inputs

Ask. Then inspect.

The parser matches explicit aliases. Intent is selected separately; no language model runs.

Invented catalog: Lumen One, Lumen One Pro and Lumen Arc. “Lumen” is deliberately ambiguous.

Saved user selection

None. A new exact product does not inherit an unrelated old selection.

After remembering One, try “Compare it with Lumen Arc”. Only user-selected product IDs carry forward. Chat text and assistant claims never become evidence.

Simulated provider boundary

These are locally constructed structured claims, not live model output. No API call or credential is involved.

Choose included evidence records 8 of 9
Included synthetic evidence

03 / Actual decision

A route, with reasons.

Actual routeDeterministic answerverified-fact

An exact product fact can be answered from eligible evidence without a model.

Deterministic answer. An exact product fact can be answered from eligible evidence without a model. Lumen One: USD 240. Matches the selected expected route.

This compares a deterministic route with a selected expectation. It is not a model-quality score.
Selected products
Lumen One
Context carried
No
Eligible sources
1 of 8 included
Provider status
not-needed

Deterministic facts

Lumen One · price

USD 240Source: one-us-v1 ↓

Structured claim inspection

Put the claim beside its evidence.

No simulated response was submitted. In explanation mode, choose a simulated response to inspect its product, value and citation fields.

This view compares the actual submitted fields with selected products and eligible supplied sources. The core result remains authoritative. Matching structured fields does not prove source truth or natural-language model quality.

Inspect the exact input and request

Evaluation input

{
  "message": "What is the price of Lumen One?",
  "intent": "fact",
  "field": "price",
  "region": "us",
  "now": "2026-10-21T12:00:00Z",
  "previousProductIds": [],
  "providerAvailable": true
}

Model request boundary

null

No data is sent. There is no connected model, telemetry or persistent query history.

04 / Inspect every included source

Eligibility comes before an answer.

The clock is an explicit input. Validity starts inclusively and expiry is exclusive. Duplicate IDs, unknown publication states and conflicting facts fail closed.

View only. Filters do not change included evidence, the decision or your case export.

Showing 8 of 8 included sources · 1 accepted · 7 rejected

Why sources were rejected 6 reason types

Reason occurrences; one source can have several reasons.

  • Different product2different-product
  • Disabled record1disabled
  • Expired1expired
  • Not yet valid1not-yet-valid
  • Not explicitly published1unpublished
  • Wrong region1wrong-region

Accepted evidence

1 records

one-us-v1

Accepted

Lumen One · US

priceUSD 240
  • Eligible
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "one-us-v1",
  "productId": "lumen-one",
  "region": "us",
  "published": true,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "USD 240",
    "connection": "USB-C",
    "mounting": "Table stand"
  }
}

Rejected evidence

7 records

pro-us-v1

Rejected

Lumen One Pro · US

priceUSD 360
  • Different product
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "pro-us-v1",
  "productId": "lumen-one-pro",
  "region": "us",
  "published": true,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "USD 360",
    "connection": "USB-C and Wi-Fi",
    "mounting": "Tripod"
  }
}

arc-us-v1

Rejected

Lumen Arc · US

priceUSD 300
  • Different product
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "arc-us-v1",
  "productId": "lumen-arc",
  "region": "us",
  "published": true,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "USD 300",
    "connection": "Wi-Fi",
    "mounting": "Wall bracket"
  }
}

one-cn-v1

Rejected

Lumen One · CN

priceCNY 1700
  • Wrong region
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "one-cn-v1",
  "productId": "lumen-one",
  "region": "cn",
  "published": true,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "CNY 1700",
    "connection": "USB-C",
    "mounting": "Table stand"
  }
}

one-expired

Rejected

Lumen One · US

priceUSD 190
  • Expired
Inspect this source record
Validity (UTC)
2026-09-01T00:00:00Z
to 2026-10-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "one-expired",
  "productId": "lumen-one",
  "region": "us",
  "published": true,
  "validFrom": "2026-09-01T00:00:00Z",
  "expiresAt": "2026-10-01T00:00:00Z",
  "facts": {
    "price": "USD 190",
    "connection": "Legacy USB"
  }
}

one-draft

Rejected

Lumen One · US

priceUSD 99
  • Not explicitly published
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
false / true
{
  "id": "one-draft",
  "productId": "lumen-one",
  "region": "us",
  "published": false,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "USD 99",
    "connection": "Unreviewed wireless"
  }
}

one-disabled

Rejected

Lumen One · US

priceUSD 5
  • Disabled record
Inspect this source record
Validity (UTC)
2026-10-01T00:00:00Z
to 2026-11-01T00:00:00Z
Publication / enabled
true / false
{
  "id": "one-disabled",
  "productId": "lumen-one",
  "region": "us",
  "published": true,
  "disabled": true,
  "validFrom": "2026-10-01T00:00:00Z",
  "expiresAt": "2026-11-01T00:00:00Z",
  "facts": {
    "price": "USD 5",
    "connection": "Disabled offer"
  }
}

one-future

Rejected

Lumen One · US

priceUSD 250
  • Not yet valid
Inspect this source record
Validity (UTC)
2026-11-01T00:00:00Z
to 2026-12-01T00:00:00Z
Publication / enabled
true / true
{
  "id": "one-future",
  "productId": "lumen-one",
  "region": "us",
  "published": true,
  "validFrom": "2026-11-01T00:00:00Z",
  "expiresAt": "2026-12-01T00:00:00Z",
  "facts": {
    "price": "USD 250",
    "connection": "USB-C"
  }
}

05 / Inspect and reproduce

The same core. In the UI and the tests.

The UI imports the TypeScript file below. The downloadable package contains these exact core bytes, synthetic fixtures, case export/replay helpers, runnable Node tests and a SHA-256 manifest. It runs without dependencies or network access.

Node.js 22.18 or later, inside the extracted folder:

node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON --test grounded-answer.test.mjs grounded-answer-cases.test.mjs

Replay a downloaded case JSON in the extracted source folder. Replay recomputes the decision and rejects mismatched output or versions. Case JSON may contain your question; keep it local.

node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON replay-grounded-case.mjs ./case.json
Read the exact executable core
/**
 * Independent, deterministic reference implementation. Synthetic inputs only.
 * No network, model API, storage, randomness, or current-clock dependency.
 * Citation validation checks exact structured facts, not natural-language quality.
 */
export type Region = "us" | "cn";
export type FactKey = "price" | "connection" | "mounting";
export type Intent = "fact" | "compare" | "explain";
export type Route = "deterministic-answer" | "model-request" | "safe-fallback";
export type Product = { id: string; name: string; aliases: readonly string[] };
export type Source = {
  id: string;
  productId: string;
  region: Region;
  published: boolean;
  disabled?: boolean;
  validFrom: string;
  expiresAt?: string | null;
  facts: Partial<Record<FactKey, string>>;
};
export type Claim = { productId: string; field: FactKey; value: string; citationId: string };
export type SimulatedResponse = { claims: readonly Claim[] };
export type Input = {
  message: string;
  intent: Intent;
  field: FactKey;
  region: Region;
  now: string;
  previousProductIds: readonly string[];
  providerAvailable: boolean;
  simulatedResponse?: SimulatedResponse;
};
export type SourceReview = { source: Source; accepted: boolean; reasons: string[] };
export type CitationReview = { valid: boolean; reasons: string[] };
export type Decision = {
  route: Route;
  reason: string;
  products: Product[];
  contextUsed: boolean;
  reviews: SourceReview[];
  facts: Claim[];
  citations: CitationReview | null;
  provider: "not-needed" | "not-called" | "unavailable" | "simulated-valid" | "simulated-rejected";
  request: { productIds: string[]; field: FactKey; evidence: { sourceId: string; productId: string; value: string }[] } | null;
};

const normalized = (value: string) => value.normalize("NFKC").toLocaleLowerCase("en-US").replace(/[^\p{L}\p{N}]+/gu, " ").trim();

/** Longest matching product aliases win; a shared family alias stays ambiguous. */
export function selectProducts(message: string, catalog: readonly Product[], previousProductIds: readonly string[], compareAcrossTurns = false) {
  const text = ` ${normalized(message)} `;
  const hits: { product: Product; start: number; end: number }[] = [];
  for (const product of catalog) {
    for (const alias of Array.from(new Set([product.name, ...product.aliases]))) {
      const term = ` ${normalized(alias)} `;
      if (term.trim().length === 0) continue;
      let start = text.indexOf(term);
      while (start !== -1) {
        hits.push({ product, start, end: start + term.length });
        start = text.indexOf(term, start + 1);
      }
    }
  }
  const specific = hits.filter(hit => !hits.some(other => other.start <= hit.start && other.end >= hit.end && other.end - other.start > hit.end - hit.start));
  const ids = Array.from(new Set(specific.map(hit => hit.product.id)));
  const refersBack = /\b(it|this|that|they|them|these|those|both|previous|other)\b/.test(normalized(message));
  const previous = Array.from(new Set(previousProductIds)).filter(id => catalog.some(product => product.id === id));
  // A new explicit selection replaces stale context. One remembered product can
  // supply the other side only when the user explicitly compares back to it.
  const addsComparisonPartner = compareAcrossTurns && previous.length === 1 && ids.length === 1
    && /\b(compare|compared|comparing|with|against|versus|vs|than)\b/.test(normalized(message));
  const contextUsed = refersBack && previous.length > 0 && (ids.length === 0 || addsComparisonPartner);
  const selectedIds = contextUsed ? Array.from(new Set([...previous, ...ids])) : ids;
  // A single alias mapping to multiple products must never choose the first one.
  const ambiguous = specific.some(hit => specific.some(other => other.start === hit.start && other.end === hit.end && other.product.id !== hit.product.id));
  return { products: selectedIds.map(id => catalog.find(product => product.id === id)!), ambiguous, contextUsed };
}

/** Require a real UTC calendar instant; Date.parse alone normalizes invalid dates. */
function utcInstant(value: string) {
  const parts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?Z$/.exec(value);
  if (!parts) return NaN;
  const time = Date.parse(value);
  const date = new Date(time);
  const actual = [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()];
  const expected = parts.slice(1, 7).map(part => Number(part ?? 0));
  expected.push(Number((parts[7] ?? "").padEnd(3, "0")));
  return actual.every((part, index) => part === expected[index]) ? time : NaN;
}

/** Expiry is exclusive: a source expires exactly at expiresAt. */
export function reviewSources(sources: readonly Source[], productIds: readonly string[], input: Pick<Input, "region" | "now" | "field">): SourceReview[] {
  const now = utcInstant(input.now);
  const counts = new Map<string, number>();
  for (const source of sources) counts.set(source.id, (counts.get(source.id) ?? 0) + 1);
  return sources.map(source => {
    const reasons: string[] = [];
    const from = utcInstant(source.validFrom);
    const until = source.expiresAt == null ? Infinity : utcInstant(source.expiresAt);
    if (!productIds.includes(source.productId)) reasons.push("different-product");
    if (source.region !== input.region) reasons.push("wrong-region");
    if (source.published !== true) reasons.push("unpublished");
    if (source.disabled !== undefined && source.disabled !== false) reasons.push("disabled");
    if (!Number.isFinite(now) || !Number.isFinite(from) || (until !== Infinity && !Number.isFinite(until)) || from >= until) reasons.push("invalid-time-window");
    else {
      if (now < from) reasons.push("not-yet-valid");
      if (now >= until) reasons.push("expired");
    }
    if ((counts.get(source.id) ?? 0) !== 1) reasons.push("duplicate-source-id");
    const value = source.facts[input.field];
    if (typeof value !== "string" || !value.trim()) reasons.push("missing-requested-fact");
    return { source, accepted: reasons.length === 0, reasons: reasons.length ? reasons : ["eligible"] };
  });
}

/** Every cited claim must match an allowed product, requested field and exact fact. */
export function validateCitations(response: SimulatedResponse, accepted: readonly Source[], productIds: readonly string[], field: FactKey): CitationReview {
  const reasons: string[] = [];
  if (!Array.isArray(response.claims) || response.claims.length === 0) return { valid: false, reasons: ["empty-claims"] };
  if (response.claims.length > 32) return { valid: false, reasons: ["too-many-claims"] };
  for (const claim of response.claims as readonly Claim[]) {
    if (!claim || typeof claim !== "object" || ![claim.productId, claim.field, claim.value, claim.citationId].every(value => typeof value === "string" && value.length > 0)) { reasons.push("malformed-claim"); continue; }
    const source = accepted.find(candidate => candidate.id === claim.citationId);
    if (!source) reasons.push("unknown-or-ineligible-citation");
    if (!productIds.includes(claim.productId)) reasons.push("unselected-product");
    if (claim.field !== field) reasons.push("unrequested-field");
    if (source && source.productId !== claim.productId) reasons.push("citation-product-mismatch");
    if (source && source.facts[claim.field] !== claim.value) reasons.push("unsupported-fact");
  }
  for (const productId of productIds) {
    if (!response.claims.some(claim => claim && claim.productId === productId && claim.field === field)) reasons.push("missing-product-coverage");
  }
  return { valid: reasons.length === 0, reasons: Array.from(new Set(reasons)) };
}

/** Explanations produce an inspectable request boundary, never a live model call. */
export function evaluateGroundedAnswer(input: Input, catalog: readonly Product[], sources: readonly Source[]): Decision {
  const selection = selectProducts(input.message, catalog, input.previousProductIds, input.intent === "compare");
  const products = selection.products;
  const productIds = products.map(product => product.id);
  const reviews = reviewSources(sources, productIds, input);
  const result: Decision = { route: "safe-fallback", reason: "unknown-product", products, contextUsed: selection.contextUsed, reviews, facts: [], citations: null, provider: "not-called", request: null };
  if (!input.message.trim()) return { ...result, reason: "empty-question" };
  if (selection.ambiguous) return { ...result, reason: "ambiguous-product-name" };
  if (products.length === 0) return result;
  if (products.length > 2 || (input.intent !== "compare" && products.length !== 1)) return { ...result, reason: "choose-one-product" };
  if (input.intent === "compare" && products.length !== 2) return { ...result, reason: "comparison-needs-two-products" };
  const accepted = reviews.filter(review => review.accepted).map(review => review.source);
  if (products.some(product => !accepted.some(source => source.productId === product.id))) return { ...result, reason: "no-eligible-evidence" };
  for (const product of products) {
    const values = new Set(accepted.filter(source => source.productId === product.id).map(source => source.facts[input.field]));
    if (values.size !== 1) return { ...result, reason: "conflicting-evidence" };
  }
  const facts = products.map(product => {
    const source = accepted.filter(candidate => candidate.productId === product.id).sort((a, b) => a.id.localeCompare(b.id))[0];
    return { productId: product.id, field: input.field, value: source.facts[input.field]!, citationId: source.id };
  });
  if (input.intent !== "explain") return { ...result, route: "deterministic-answer", reason: input.intent === "compare" ? "verified-comparison" : "verified-fact", facts, provider: "not-needed" };
  if (input.providerAvailable !== true) return { ...result, reason: "provider-unavailable", provider: "unavailable" };
  const request = { productIds, field: input.field, evidence: accepted.map(source => ({ sourceId: source.id, productId: source.productId, value: source.facts[input.field]! })) };
  if (!input.simulatedResponse) return { ...result, route: "model-request", reason: "eligible-model-request", request };
  const citations = validateCitations(input.simulatedResponse, accepted, productIds, input.field);
  if (!citations.valid) return { ...result, reason: "invalid-simulated-citations", provider: "simulated-rejected", request, citations };
  return { ...result, route: "model-request", reason: "validated-simulated-claims", provider: "simulated-valid", request, facts: [...input.simulatedResponse.claims], citations };
}

Read the implementation account

From a visible boundary
to the engineering decisions.

Read the grounded AI article ↗See the commerce product evidence ↗Explore the independent release lab ↗