Skip to content

API Reference parrot.knowledge.contracts.models

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

parrot.knowledge.contracts.models

View source

Typed contract models — the normative data plane of FEAT-539.

Every model here is a Pydantic v2 model with closed taxonomies, bounded payloads and stable provenance paths so that any extracted field can be traced back to a quote in an indexed document.

:class:ContractCard is a sibling of :class:~parrot.knowledge.bookstore.models.BookCard, not a subclass: the two card families share only the :class:TocEntry row type and the "one slug, one tree, one card" identity rule.

Design contract: spec sdd/specs/contracts-card-ontology.spec.md §2.

Attribute ANSWER_KINDS

Type: tuple[str, ...]

Attribute AnswerKind

Alias AnswerProvenance

Re-exported from parrot.knowledge.common.provenance.AnswerProvenance.

Class AnswerRecord

One audited answer, persisted before the answer is released.

Denials and empty answers are retained: the audit trail is the reason a citation can later be retired and suppressed.

Fields:

Field Type Default Description
answer_id str
asked_at datetime
user str
question str
answer_kind AnswerKind
pattern Optional[str] None
answer Optional[str] None
citations list[Citation]
authorization AuthorizationOutcome
retired_by Optional[str] None
retired_at Optional[datetime] None
retirement_reason Optional[str] None

Attributes:

Attribute Type Description
retired bool True once this answer has been retired by an owner.

Class AuthorizationOutcome

The recorded result of the shared authorization gate.

Fields:

Field Type Default Description
allowed bool
principal Optional[str] None
matched_rule Optional[str] None
reason Optional[str] None

Attribute CONTRACT_STATUSES

Type: tuple[str, ...]

Attribute CONTRACT_TYPES

Type: tuple[str, ...]

Attribute CardOrigin

Class Citation

One released evidence pointer, pinned to an immutable version.

version_n and source_sha256 are part of the citation identity so a historical node id can never silently resolve against current text.

Fields:

Field Type Default Description
contract_id str
title str ''
node_id str
quote str
page Optional[int] None
verification VerificationState 'extracted'
version_n int 1
source_sha256 str ''

Attributes:

Attribute Type Description
key tuple[str, str] The (contract_id, node_id) pair used by retirement rules.

Class ContractAnswer

The single answer shape shared by the ReAct agent and fixed flow.

Kind invariants (spec §2 "Answering and authorization"):

  • lookup — requires answer text and at least one citation.
  • interpretation_required — requires a handoff and carries no judgment answer.
  • not_found / out_of_scope / denied — carry no fabricated answer, evidence or handoff.

provenance is always derived from the surviving citations, never taken from model output.

Fields:

Field Type Default Description
answer_kind AnswerKind
answer Optional[str] None
citations list[Citation]
provenance AnswerProvenance 'extracted'
handoff Optional[HandoffBrief] None
pattern Optional[str] None
reason Optional[str] None

Class ContractCard

The durable catalog card for one indexed contract document.

contract_id doubles as the PageIndex tree_name — one slug, one tree, one card — mirroring the bookstore identity rule without inheriting from BookCard.

Fields:

Field Type Default Description
contract_id str
tree_name str ''
title str
contract_type ContractType 'other'
status ContractStatus 'unknown'
parties list[Party]
signatories list[Signatory]
term TermSpec
governing_law Optional[str] None
parent_contract_id Optional[str] None
supersedes_contract_id Optional[str] None
obligations list[Obligation]
summary str ''
topics list[str]
owner_employee_id Optional[str] None
department Optional[str] None
language str 'en'
source_uri str
source_path Optional[str] None
source_sha256 str ''
source_format SourceFormat 'pdf'
page_count Optional[int] None
toc list[TocEntry]
toc_digest str ''
field_provenance dict[str, FieldProvenance]
verification VerificationState 'extracted'
verified_by Optional[str] None
verified_at Optional[datetime] None
stale_fields list[str]
card_origin CardOrigin 'llm'
termination_confirmed bool False
terminated_on Optional[date] None
versions list[ContractVersion]
revision int 1
active bool True
added_at Optional[datetime] None
updated_at Optional[datetime] None

Attributes:

Attribute Type Description
counterparties list[Party] Every party that is not our own entity.

Method ContractCard.brief

Compact dict for bounded tool/list payloads.

brief() -> dict[str, Any]

Returns: dict[str, Any] — The fields an agent needs to pick a contract, without the ToC, obligations or provenance payloads.

Class ContractHeaderDraft

Structured output of the single bounded header extraction call.

Deliberately carries no derived facts: status, notice_deadline, next_renewal_date and parent_contract_id are computed in Python from these evidenced values (spec §2 carding steps 5–6).

Fields:

Field Type Default Description
title Extracted[str]
contract_type Extracted[ContractType]
effective_date Extracted[date]
expiration_date Extracted[date]
initial_term_months Extracted[int]
auto_renew Extracted[bool]
renewal_period_months Extracted[int]
notice_days Extracted[int]
governing_law Extracted[str]
parent_contract_title Extracted[str]
parties list[PartyDraft]
signatories list[SignatoryDraft]
summary str ''
topics list[str]
language str 'en'

Class ContractRelation

One active, judged edge between two contracts.

Fields:

Field Type Default Description
source_contract_id str
target_contract_id str
kind Literal['conflicts_with', 'references_obligation']
source_obligation_id Optional[str] None
target_obligation_id Optional[str] None
confidence float 0.0
rationale str ''
origin Literal['llm', 'manual'] 'llm'
judged_at Optional[datetime] None
active bool True

Attribute ContractStatus

Attribute ContractType

Class ContractVersion

One recorded revision of a card, with its contractual interval.

Recorded time (recorded_at, revision) and contractual effective time (valid_from / valid_to) answer different questions and are deliberately kept apart. Unknown effective dates stay None instead of silently becoming today.

Fields:

Field Type Default Description
n int
revision int 1
valid_from Optional[date] None
valid_to Optional[date] None
kind VersionKind 'original'
amended_by Optional[str] None
source_sha256 str ''
card_snapshot dict[str, Any]
recorded_at Optional[datetime] None
evidence_ref Optional[str] None

Method ContractVersion.in_force

Whether this version is contractually in force on as_of.

in_force(as_of: date) -> bool

Parameter Type Default Description
as_of date The date to test.

Returns: bool — True when valid_from <= as_of < valid_to; an unknown valid_from never claims to be in force.

Alias Evidence

Re-exported from parrot.knowledge.common.provenance.Evidence.

Alias Extracted

Re-exported from parrot.knowledge.common.provenance.Extracted.

Alias FieldProvenance

Re-exported from parrot.knowledge.common.provenance.FieldProvenance.

Class HandoffBrief

What a human needs to adjudicate an interpretation request.

Fields:

Field Type Default Description
question str
why_judgment str
located_clauses list[Citation]
related_contracts list[str]
suggested_owner Optional[str] None

Class IngestItemReport

Per-file outcome inside a batch ingestion report.

Fields:

Field Type Default Description
source_uri str
outcome IngestOutcome
contract_id Optional[str] None
reason str ''
publication_state Optional[PublicationState] None

Method IngestItemReport.from_result

Build a report row from a single :class:IngestResult.

from_result(result: IngestResult) -> 'IngestItemReport'

Parameter Type Default Description
result IngestResult

Returns: 'IngestItemReport'

Attribute IngestOutcome

Class IngestReport

Deterministic per-batch ingestion report.

Fields:

Field Type Default Description
items list[IngestItemReport]
cursor_advanced bool False
cursor Optional[str] None

Attributes:

Attribute Type Description
added int Number of newly carded documents.
updated int Number of documents that produced a new revision.
skipped int Number of documents deliberately skipped, with a reason.
errors int Number of documents that failed with a recorded reason.

Method IngestReport.summary

Compact counts for logs and operator output.

summary() -> dict[str, int]

Returns: dict[str, int]

Class IngestResult

The outcome of ingesting one source document.

card is None for skipped/error outcomes, and reason is always explicit (unchanged content, no extractable text, …).

Fields:

Field Type Default Description
card Optional[ContractCard] None
outcome IngestOutcome
reason str ''
source_uri str ''
publication_state Optional[PublicationState] None

Alias MAX_QUOTE_CHARS

Re-exported from parrot.knowledge.common.provenance.MAX_QUOTE_CHARS.

Attribute OBLIGATION_KINDS

Type: tuple[str, ...]

Attribute OBLIGORS

Type: tuple[str, ...]

Class Obligation

One clause-level commitment, quoted verbatim from the source.

Fields:

Field Type Default Description
obligation_id str
contract_id str
kind ObligationKind 'other'
obligor Obligor 'counterparty'
text str
node_id str
page Optional[int] None
standard_id Optional[str] None
due_date Optional[date] None
recurrence Optional[str] None
verification VerificationState 'extracted'
provenance FieldProvenance
active bool True

Class ObligationClauseDraft

One evidenced obligation clause candidate.

IDs, standard resolution and provenance are added deterministically during assembly, never by the model.

Fields:

Field Type Default Description
excerpt str ''
node_id str
page Optional[int] None
kind ObligationKind 'other'
obligor Obligor 'counterparty'
standard_name Optional[str] None
due_date Optional[date] None
recurrence Optional[str] None
confidence float 0.0

Attribute ObligationKind

Class ObligationsDraft

Structured output of one bounded obligation-section call.

Fields:

Field Type Default Description
clauses list[ObligationClauseDraft]

Attribute Obligor

Attribute PARTY_ROLES

Type: tuple[str, ...]

Attribute PROVENANCE_ORIGINS

Type: tuple[str, ...]

Class Party

One legal entity bound by a contract.

Fields:

Field Type Default Description
party_id str
name str
role PartyRole 'other'
is_us bool False

Class PartyAlias

One normalized alias mapped onto a canonical party identity.

Fields:

Field Type Default Description
alias str
party_id str
actor Optional[str] None
created_at Optional[datetime] None

Class PartyDraft

Evidenced party candidate from the header extraction call.

Fields:

Field Type Default Description
name str
role PartyRole 'other'
is_us bool False
evidence Optional[Evidence] None
confidence float 0.0

Attribute PartyRole

Alias ProvenanceOrigin

Re-exported from parrot.knowledge.common.provenance.ProvenanceOrigin.

Class PublicationRecord

One durable outbox row for a card revision and publication target.

The (tenant_id, contract_id, version_n, revision, target) tuple is the queue identity; run_id is stable per revision so an acknowledged-but-unrecorded commit can be recovered instead of republished.

Fields:

Field Type Default Description
tenant_id str
contract_id str
version_n int 1
revision int 1
target PublicationTarget
run_id str
payload dict[str, Any]
state PublicationState 'pending'
receipt Optional[str] None
attempts int 0
last_error Optional[str] None
created_at Optional[datetime] None
updated_at Optional[datetime] None

Attributes:

Attribute Type Description
key tuple[str, str, int, int, str] The durable queue identity of this record.

Attribute PublicationState

Attribute PublicationTarget

Attribute RELATION_KINDS

Type: tuple[str, ...]

Class RelationJudgement

One logged LLM relation judgement, including negative outcomes.

Judgements are made only at explicit ingest/relate time and are invalidated when either endpoint's source hash changes.

Fields:

Field Type Default Description
judgement_id str
source_contract_id str
target_contract_id str
outcome RelationKind 'none'
source_sha256 str ''
target_sha256 str ''
source_obligation_id Optional[str] None
target_obligation_id Optional[str] None
confidence float 0.0
rationale str ''
model str ''
judged_at Optional[datetime] None
origin Literal['llm', 'manual'] 'llm'
active bool True

Attribute RelationKind

Attribute SOURCE_FORMATS

Type: tuple[str, ...]

Class Signatory

One person who signed on behalf of a party.

Fields:

Field Type Default Description
person_id str
name str
party_id str
title Optional[str] None
signed_on Optional[date] None
employee_id Optional[str] None

Class SignatoryDraft

Evidenced signatory candidate from the header extraction call.

Fields:

Field Type Default Description
name str
party_name Optional[str] None
title Optional[str] None
signed_on Optional[date] None
employee_id Optional[str] None
evidence Optional[Evidence] None
confidence float 0.0

Class SourceDeltaToken

The committed opaque continuation token for one configured source.

Fields:

Field Type Default Description
source_uri str
token str ''
updated_at Optional[datetime] None

Attribute SourceFormat

Class SourceItem

Stable identity of one remote source file across renames/moves.

Recorded so a delta rename is not mistaken for a new document and a tombstone retracts the right contract.

Fields:

Field Type Default Description
source str
drive_id str
item_id str
current_uri str ''
name Optional[str] None
contract_id Optional[str] None
sha256 Optional[str] None
deleted bool False
last_seen_at Optional[datetime] None

Class TermSpec

Duration, renewal and notice facts of an agreement.

notice_deadline and next_renewal_date are derived in Python (spec §2 carding step 6), never extracted by a model.

Fields:

Field Type Default Description
effective_date Optional[date] None
expiration_date Optional[date] None
initial_term_months Optional[int] None
auto_renew bool False
renewal_period_months Optional[int] None
notice_days Optional[int] None
notice_deadline Optional[date] None
next_renewal_date Optional[date] None

Alias TocEntry

Re-exported from parrot.knowledge.bookstore.models.TocEntry.

Alias UNSUBSTANTIATED_CONFIDENCE_CAP

Re-exported from parrot.knowledge.common.provenance.UNSUBSTANTIATED_CONFIDENCE_CAP.

Attribute VERIFICATION_STATES

Type: tuple[str, ...]

Attribute VERSION_KINDS

Type: tuple[str, ...]

Alias VerificationState

Re-exported from parrot.knowledge.common.provenance.VerificationState.

Attribute VersionKind

Function card_snapshot_payload

Serialise card for a :class:ContractVersion snapshot.

Drops the card's own versions list so version history cannot grow recursively with every recorded revision.

card_snapshot_payload(card: ContractCard) -> dict[str, Any]

Parameter Type Default Description
card ContractCard The card to snapshot.

Returns: dict[str, Any] — A JSON-mode dict without the versions key.

Function derive_provenance

Derive the top-level provenance of an answer from its citations.

derive_provenance(citations: list[Citation]) -> AnswerProvenance

Parameter Type Default Description
citations list[Citation] The surviving, verified citations of an answer.

Returns: AnswerProvenance — verified when every citation is verified, mixed when verified and unverified citations coexist, otherwise extracted (also the conservative value for empty evidence).

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