Skip to content

API Reference parrot.knowledge.wiki.charter

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

parrot.knowledge.wiki.charter

View source

Editorial charter models, YAML loader, and fingerprinting (FEAT-402).

The editorial charter is the versioned policy artifact that drives every supervised-ingestion triage decision: scope include/exclude rules, scoring-dimension weights, admit/reject thresholds, routing destinations, calibration policy, and the few-shot examples loop that anchors the triage LLM against past human decisions.

Design notes:

  • All models follow the same Pydantic v2 pattern used throughout the wiki package (see parrot.knowledge.wiki.models.WikiConfig).
  • The composite score is always computed in application code from the charter's dimension weights — the charter only stores the weights and thresholds; the LLM never sees or emits a composite (spec Data Models, Non-Goals).
  • Charter.fingerprint is a sha256 hash of the raw bytes of the YAML file as read from disk, computed once at load_charter time. It is NOT a field in the YAML document itself — any edit to the file (even whitespace) changes the fingerprint and therefore versions every decision made against it.
  • examples_file (when set) is an appendable JSONL file of :class:TriageExample rows — human decisions accumulate here via :func:append_example without needing to rewrite the whole charter YAML document.
  • This module performs only synchronous, in-memory work (YAML parse + Pydantic validation) and synchronous file I/O. It is invoked from CLI setup, before the async ingestion pipeline starts — no async wrapper is needed here.

Class Amendment

A single entry in the charter's editorial amendment history.

Fields:

Field Type Default Description
version str The charter version this amendment introduced.
date date The date the amendment was made.
change str Prose description of what changed.
source str Who/what proposed the change (e.g. "manual" or an autotune-calibration proposal reference).

Class CalibrationPolicy

Stratified audit sampling and gray-zone calibration policy.

Fields:

Field Type Default Description
near_fraction float 0.6 Fraction of the audit sample drawn from documents near the admit/reject thresholds (default 0.6).
uniform_fraction float 0.4 Fraction of the audit sample drawn uniformly at random across all triaged documents (default 0.4).
min_agreement float 0.9 Minimum acceptable human/router agreement rate on the audited sample.
on_low_agreement Literal['widen_gray_zone', 'halt', 'warn'] 'widen_gray_zone' Action to propose when agreement drops below min_agreement.
gray_zone_step float 0.05 How much to widen the gray zone (per threshold) when agreement is low.
autotune Literal['off', 'propose'] 'propose' Calibration write mode. v1 supports only "off" and "propose" — charter amendments are never auto-applied.

Class Charter

The editorial charter: the versioned policy artifact for triage.

Fields:

Field Type Default Description
version str Charter version identifier (bumped on every amendment).
scope CharterScope Include/exclude scope rules.
weights dict[str, float] Scoring-dimension weights; keys must be exactly {"density", "novelty", "durability"}, each in [0, 1], summing to ~1.0.
thresholds Thresholds Admit/reject composite-score thresholds.
destinations list[str] Valid routing destinations. Defaults to ["wiki", "archive", "discard"].
calibration CalibrationPolicy Audit-sampling and gray-zone calibration policy.
examples list[TriageExample] Inline few-shot examples embedded in the charter YAML.
examples_file Path | None None Optional path to an appendable JSONL file of additional :class:TriageExample rows (see :func:append_example).
amendments list[Amendment] Editorial amendment history.
taxonomy Taxonomy
fingerprint str '' sha256 hex digest of the raw charter file bytes. Populated by :func:load_charter; NOT part of the YAML document and not validated as an input field.

Method Charter.validate_weights

Ensure weights cover exactly the known dimensions and sum to 1.

Mirrors WikiConfig.validate_search_weights (parrot/knowledge/wiki/models.py).

validate_weights(v: dict[str, float]) -> dict[str, float]

Parameter Type Default Description
v dict[str, float] The raw weights mapping.

Returns: dict[str, float] — The validated mapping unchanged.

Raises:

  • ValueError — If keys don't match DIMENSION_NAMES, any weight is outside [0, 1], or the sum deviates from 1.0 by more than 0.01.

Method Charter.validate_destinations

Ensure every listed destination is a known routing target.

validate_destinations(v: list[str]) -> list[str]

Parameter Type Default Description
v list[str] The raw destinations list.

Returns: list[str] — The validated list unchanged.

Raises:

  • ValueError — If any entry is not in DESTINATIONS.

Class CharterScope

Editorial scope: what belongs in the wiki and what does not.

Fields:

Field Type Default Description
include list[CharterScopeRule] Rules describing admissible content categories.
exclude list[CharterScopeRule] Rules describing content that should never be admitted.

Class CharterScopeRule

A single scope rule (an include or exclude reason).

Fields:

Field Type Default Description
id str Short, stable identifier for the rule (e.g. "decisions").
description str Prose description used as LLM triage context.

Attribute DEFAULT_TAXONOMY

Attribute DESTINATIONS

Type: frozenset[str]

Attribute DIMENSION_NAMES

Type: frozenset[str]

Class Taxonomy

Closed document taxonomy for inbox classification.

Fields:

Field Type Default Description
default_kind str 'note' Document kind selected when classification is unknown.
max_tags int 8 Maximum number of normalized tags to retain.
kinds list[TaxonomyKind] Declared document kinds and their wiki category mappings.

Method Taxonomy.kind

Return the declared kind, or None.

kind(kind_id: str) -> TaxonomyKind | None

Parameter Type Default Description
kind_id str Identifier of the requested document kind.

Returns: TaxonomyKind | None — The matching taxonomy kind, if declared.

Class TaxonomyKind

One allowed document kind and its wiki category.

Fields:

Field Type Default Description
id str Stable kebab-case identifier for the document kind.
description str Human-readable explanation of the kind.
category str Target :class:WikiPageCategory value.
tag_hints list[str] Suggested tags for documents of this kind.

Class Thresholds

Composite-score admission thresholds.

The half-open interval [reject, admit) is the gray zone that requires heavy-tier escalation and/or human review.

Fields:

Field Type Default Description
admit float Composite scores at or above this value are admitted.
reject float Composite scores below this value are rejected.

Method Thresholds.route

Route a composite score to an admission band.

route(composite: float) -> Literal['admit', 'gray', 'reject']

Parameter Type Default Description
composite float The weighted composite score in [0, 1].

Returns: Literal['admit', 'gray', 'reject'] — "admit" if composite >= admit, "reject" if composite < reject, otherwise "gray".

Class TriageExample

A single few-shot example anchoring the triage LLM.

Fields:

Field Type Default Description
summary str Short summary of the example document.
why str Rationale for the destination assigned to the example.
destination Literal['wiki', 'archive', 'discard'] | None None The routing destination this example illustrates.

Alias WikiPageCategory

Re-exported from parrot.knowledge.wiki.models.WikiPageCategory.

Function append_example

Append a human triage decision to the charter's examples file.

The examples file is a JSONL file (one :class:TriageExample per line) so human decisions can be appended without rewriting the whole charter YAML document. This feeds the few-shot loop described in the spec (Module 1).

append_example(charter: Charter, example: TriageExample, path: Path | None = None) -> Path

Parameter Type Default Description
charter Charter The charter the example belongs to. Used to resolve the default target file (charter.examples_file) when path is not given.
example TriageExample The example to append.
path Path | None None Optional explicit target file, overriding charter.examples_file.

Returns: Path — The path the example was appended to.

Raises:

  • ValueError — If neither path nor charter.examples_file is set.

Function default_taxonomy

Return an independent copy of the built-in taxonomy.

default_taxonomy() -> Taxonomy

Returns: Taxonomy — A deep copy of :data:DEFAULT_TAXONOMY.

Function load_charter

Load, validate, and fingerprint an editorial charter YAML file.

load_charter(path: Path) -> Charter

Parameter Type Default Description
path Path Path to the charter YAML file.

Returns: Charter — A validated :class:Charter instance with .fingerprint populated as the sha256 hex digest of the raw file bytes.

Raises:

  • FileNotFoundError — If path does not exist.
  • pydantic.ValidationError — If the charter document fails model validation (bad weights, bad threshold ordering, etc).

Attribute logger

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