Skip to content

API Reference parrot.knowledge.wiki.review

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.wiki.review

View source

JSONL review manifest layer for supervised wiki ingestion (FEAT-402).

Implements the HITL contract described in the spec (§2 Overview, Module 2): wikitoolkit ingest --dry-run writes a JSONL manifest, a human edits the decision field on each row, and --review applies the edited decisions. This module owns:

  • The triage data models shared by the router (triage.py, TASK-2071) and the manifest: :class:DimensionScores, :class:Claim, :class:TriageOutput.
  • The manifest row models: :class:ManifestRunHeader (line 1) and :class:ManifestDocEntry (one per triaged document).
  • :class:ManifestWriter / :class:ManifestReader for the JSONL file itself.
  • :func:stratified_sample — the charter-configurable 60/40 near-threshold/uniform audit sampler used by --auto mode.
  • :func:agreement_rate — human-vs-proposed agreement on decided entries.
  • :func:propose_gray_zone_widening — a propose-only calibration helper; v1 never auto-writes charter changes (spec §1 Non-Goals, §7).

Design notes:

  • TriageOutput deliberately has no composite field — the LLM only scores dimensions; the weighted composite is always computed in Python from the charter's weights (triage.py, TASK-2071). Do not add one.
  • Every manifest line carries an explicit kind discriminator ("run_header" or "doc") so the reader is order-tolerant.
  • All I/O here is synchronous — manifest read/write happens outside the async apply pipeline (CLI setup / HITL edit step), matching the pattern established in charter.py (TASK-2069).

Alias CalibrationPolicy

Re-exported from parrot.knowledge.wiki.charter.CalibrationPolicy.

Class Claim

A single claim extracted from a document during triage.

Fields:

Field Type Default Description
text str The claim text.
grounded bool | None None Whether the claim was found to be grounded against the existing GraphIndex plane. None until novelty scoring fills it in (triage.py).

Attribute DOC_ACTIONS

Type: frozenset[str]

Class DimensionScores

Per-dimension triage scores, each in [0, 1].

Fields:

Field Type Default Description
density float Information density — how much admissible content per unit of document.
novelty float How much the document adds beyond what the wiki already covers (grounding-backed; see triage.py NoveltyScorer).
durability float Long-term relevance of the content.

Class ManifestDocEntry

A single document row in a JSONL review manifest.

Fields:

Field Type Default Description
kind Literal['doc'] 'doc' Discriminator, always "doc".
source_uri str Identifier of the source document.
file_hash str Content hash of the source document.
briefing str The triage briefing (see :class:TriageOutput).
scores DimensionScores Per-dimension triage scores.
composite float The weighted composite score, computed in code from the charter weights (never emitted by the LLM).
proposed_action Literal['admit', 'archive', 'discard'] The router's proposed destination.
claims list[Claim] Claims extracted from the document.
decision Literal['admit', 'archive', 'discard'] | None None The final decision. None in a fresh --dry-run manifest; filled by a human edit or --auto thresholding.
decision_source Literal['heuristic', 'model', 'human', 'auto'] | None None Where the decision came from.
audit_sample bool False Whether this entry was flagged for audit review by :func:stratified_sample.
audit_stratum str | None None Which stratum the entry was sampled from ("near_threshold" or "uniform") when audit_sample is true.

Class ManifestParseError

Raised when a JSONL manifest line cannot be parsed or validated.

The error message always names the offending 1-based line number so a human editing the manifest by hand can find and fix the mistake.

Class ManifestReader

Parses and validates a JSONL review manifest, including human edits.

Parameter Type Default Description
path Path Manifest file path to read.

Attributes:

Attribute Type Description
path Manifest file path to read.

Method ManifestReader.read

Read and validate the manifest.

read() -> tuple[ManifestRunHeader, list[ManifestDocEntry]]

Returns: tuple[ManifestRunHeader, list[ManifestDocEntry]] — A (header, entries) tuple.

Raises:

  • ManifestParseError — If a line is malformed JSON, has an unknown kind, fails model validation (e.g. an invalid hand-edited decision value), or the run header is missing/duplicated. The error message always names the offending 1-based line number.

Class ManifestRunHeader

The first line of a JSONL review manifest: run-level metadata.

Fields:

Field Type Default Description
kind Literal['run_header'] 'run_header' Discriminator, always "run_header".
charter_sha256 str sha256 fingerprint of the charter used this run.
charter_version str Charter version used this run.
mode Literal['dry-run', 'review', 'interactive', 'auto'] The CLI mode that produced this manifest.
novelty_backend Literal['grounding', 'search-proxy'] Which novelty-scoring backend ran this run — "grounding" when the GraphIndex plane exists, or "search-proxy" as the fallback.
counts dict[str, int] Summary counts (e.g. proposed action tallies).
created_at str ISO-8601 timestamp string.

Class ManifestWriter

Writes a JSONL review manifest: one run-header line + one doc line each.

Parameter Type Default Description
path Path Target manifest file path. Parent directories are created if needed at write time.

Attributes:

Attribute Type Description
path Target manifest file path.

Method ManifestWriter.write

Write the run header followed by one line per doc entry.

write(header: ManifestRunHeader, entries: list[ManifestDocEntry]) -> Path

Parameter Type Default Description
header ManifestRunHeader The run-header row (always written first).
entries list[ManifestDocEntry] The doc entries to write, in order.

Returns: Path — The path the manifest was written to.

Alias Thresholds

Re-exported from parrot.knowledge.wiki.charter.Thresholds.

Class TriageOutput

Structured output produced by the triage LLM (ask_structured).

Fields:

Field Type Default Description
briefing str 2-3 sentence summary, reused as the ingester hint.
scores DimensionScores Per-dimension scores. No composite field — the weighted composite is always computed in code from the charter's weights, never emitted by the LLM.
claims list[Claim] Claims extracted from the document (capped per charter config; used for novelty scoring and, behind the experimental --extract flag, claim-level admission).
sensitive bool False When true, forces discard regardless of composite score (spec §5 acceptance criteria).
category_hint str | None None Optional suggested wiki page category.

Function agreement_rate

Compute the human/router agreement rate on decided entries.

agreement_rate(entries: list[ManifestDocEntry]) -> float | None

Parameter Type Default Description
entries list[ManifestDocEntry] The manifest doc entries to evaluate.

Returns: float | None — The fraction of entries with a non-null decision where decision == proposed_action, rounded to 4 decimals. None when no entry has been decided yet.

Attribute logger

Function propose_gray_zone_widening

Propose widened gray-zone thresholds when agreement is low.

Propose-only (spec §1 Non-Goals, §7): this never mutates thresholds or writes to the charter. It only returns a new :class:Thresholds instance for a human to review and apply as a versioned charter edit.

propose_gray_zone_widening(thresholds: Thresholds, calibration: CalibrationPolicy, observed_agreement: float | None) -> Thresholds | None

Parameter Type Default Description
thresholds Thresholds The current charter thresholds (read-only).
calibration CalibrationPolicy The charter's calibration policy.
observed_agreement float | None The agreement rate observed on the audited sample (see :func:agreement_rate), or None if nothing has been audited yet.

Returns: Thresholds | None — A new :class:Thresholds instance with the gray zone widened by calibration.gray_zone_step on each side, or None when no widening is warranted (calibration disabled, agreement unknown, agreement already meets the bar, or the policy's low-agreement action isn't "widen_gray_zone").

Function stratified_sample

Flag a stratified audit sample on entries, in place.

Splits sample_size total picks between two strata:

  • near-threshold (near_fraction of the sample): the entries whose composite score is closest to either the admit or reject boundary — where the router is most likely to be wrong.
  • uniform (uniform_fraction of the sample): entries drawn uniformly at random from the remainder, to catch "confidently wrong" errors far from the thresholds.

Mutates the selected entries' audit_sample (set True) and audit_stratum ("near_threshold" or "uniform") fields in place. Does not return anything.

stratified_sample(entries: list[ManifestDocEntry], thresholds: Thresholds, sample_size: int, *, near_fraction: float = 0.6, uniform_fraction: float = 0.4, seed: int | None = None) -> None

Parameter Type Default Description
entries list[ManifestDocEntry] The manifest doc entries to sample from.
thresholds Thresholds The charter thresholds, used to compute distance to the nearest admit/reject boundary for the near-threshold stratum.
sample_size int Total number of entries to flag for audit. Clamped to len(entries).
near_fraction float 0.6 Fraction of sample_size drawn from the near-threshold stratum (charter-configurable; default 0.6).
uniform_fraction float 0.4 Fraction of sample_size drawn from the uniform stratum (charter-configurable; default 0.4).
seed int | None None Optional seed for the uniform draw, for deterministic tests/reruns.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally