Skip to content

API Reference parrot_tools.legal.librarian.models

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

parrot_tools.legal.librarian.models

View source

Librarian answer-layer contracts (FEAT-449 §2 Data Models, R1-R5, R12).

Two families of models:

  • Final contracts (SpanRef, ConflictNote, ReadingNote, LegalAnswer, SuppressionRecord, PayloadEntry) — the sealed, verified shapes that leave the SpanVerifier (verifier.py).
  • Draft contracts (DraftSpan, DraftReadingNote, DraftConflictNote, DraftAnswer) — what LegalLibrarianAgent.ask(structured_output=DraftAnswer) actually emits.

The load-bearing asymmetry: the LLM never emits offsets. It emits a payload_key (from the enumerated dossier) and a verbatim quote; the SpanVerifier locates the quote deterministically via str.find and derives start/end itself. Offsets from a stochastic source would defeat the existence gate (R2) — any design that has the LLM produce start/end integers directly is implementing the spec wrong.

Class ConflictNote

A flagged (never resolved) conflict between two surviving spans (R5).

Fields:

Field Type Default Description
span_a str
span_b str
note str

Attribute DEFAULT_DISCLAIMER

Constant default disclaimer text for LegalAnswer.disclaimer.

Class DraftAnswer

The structured output the librarian LLM call emits.

LegalLibrarianAgent.ask(structured_output=DraftAnswer) — the SpanVerifier turns this into the final, sealed LegalAnswer.

Fields:

Field Type Default Description
reading_order list[str]
conflicts list[DraftConflictNote]
reading_guide list[DraftReadingNote]
not_found list[str]

Class DraftConflictNote

LLM-facing draft of a flagged conflict between two draft spans.

Fields:

Field Type Default Description
span_a DraftSpan
span_b DraftSpan
note str

Class DraftReadingNote

LLM-facing draft of one reading-guide sentence.

Fields:

Field Type Default Description
text str
spans list[DraftSpan]
basis Literal['deterministic', 'llm']

Class DraftSpan

LLM-facing span citation — payload key + verbatim quote ONLY.

The verifier locates the quote deterministically (str.find) and derives start/end itself. The LLM NEVER emits offsets.

Fields:

Field Type Default Description
payload_key str
quote str

Class LegalAnswer

The final, span-verified answer (R2, R4, R12).

Fields:

Field Type Default Description
as_of date
materias list[str]
dossier list[SpanRef]
reading_order list[str]
conflicts list[ConflictNote]
reading_guide list[ReadingNote]
not_found list[str]
suppressed_count int 0
disclaimer str DEFAULT_DISCLAIMER

Class PayloadEntry

One retrievable payload the librarian may cite from (dossier_build).

Fields:

Field Type Default Description
payload_key str
payload str
content_hash str
title str
url str
as_of date
version_n int
articulo_key str
basis Literal['retrieval', 'traversal']

Class ReadingNote

One sentence of the reading guide, anchored to ≥1 surviving span.

Fields:

Field Type Default Description
text str
spans list[str]
basis Literal['deterministic', 'llm']

Class SpanRef

One verified, span-anchored citation into the primary payload.

Fields:

Field Type Default Description
kind Literal['norma', 'articulo']
id str
version_n int | None
start int
end int
quote str
content_hash str
hash_norm_version int
title str
url str
as_of date | None
basis Literal['retrieval', 'traversal']

Class SuppressionRecord

Append-only record of a fail-closed prune (R2, R4).

Persisted into the span_suppressions collection (FEAT-449 M3/M4) via SuppressionLog.append — never updated, never deleted.

Fields:

Field Type Default Description
execution_id str
suppressed_text str
claimed_anchors list[str]
reason Literal['span_not_found', 'hash_mismatch', 'quote_mismatch', 'anchor_lost', 'atom_contradicted']
user_id str | None None
created_at datetime

Function span_key

Compute the deduplication/anchor key for a SpanRef.

span_key(ref: SpanRef) -> str

Parameter Type Default Description
ref SpanRef The span reference.

Returns: str — "{id}:{version_n}:{start}-{end}".

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