Skip to content

API Reference parrot_tools.contracts.service

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

parrot_tools.contracts.service

View source

The shared contracts answer service (FEAT-539 M10).

Both answer producers — the ReAct agent and the fixed flow — go through this one service, so there is a single place where authorization, evidence verification and audit happen. A producer only ever supplies a draft; it never releases anything itself.

Order of operations, and why:

  1. Closed-set pre-triage on the question alone. Evaluative/deontic requests become interpretation_required before any retrieval, and an unclassifiable question fails closed with a typed clarification.
  2. Authorize, then retrieve — the gate runs before any protected read, including the located clauses a handoff will carry.
  3. Draft from the enumerated, bounded dossier.
  4. Verify every citation and claim against archived evidence.
  5. Audit, and only then release. If the audit write fails, the request fails: an unaudited answer is never returned. Streaming buffers the substantive answer until this whole chain has succeeded.

Class AnswerOutcome

A released answer plus its audit identity.

Fields:

Field Type Default Description
answer ContractAnswer
answer_id str
audited bool True
rejected list[dict[str, Any]]
dropped_claims list[str]

Class AnswerProducer

What the service needs from an answer producer.

A producer receives the enumerated dossier and returns a draft. It has no access to the release path.

Method AnswerProducer.draft

draft(question: str, result: RetrievalResult, dossier: Sequence[ContractCard]) -> AnswerDraft

Parameter Type Default Description
question str
result RetrievalResult
dossier Sequence[ContractCard]

Returns: AnswerDraft

Class ConfirmationRequired

A write operation needs an explicit human confirmation.

Class ContractsAnswerService

One authorization, evidence and audit gate for every answer path.

Parameter Type Default Description
retrieval ContractRetrieval The deterministic authorized retrieval.
verifier CitationVerifier The citation/claim verification gate.
producer Optional[AnswerProducer] None The draft producer (agent or fixed flow).
library Any None Optional contract library for owner-only write operations.
triage Any None Optional structured pre-triage adapter. It sees the question only, cannot generate AQL and cannot widen permissions.
now Any None Injectable clock.

Attributes:

Attribute Type Description
invalidated set[str]
catalog Any The tenant-bound catalog behind the retrieval layer.

Method ContractsAnswerService.answer

Answer a question, or explain why it cannot be answered.

answer(question: str, *, request_context: RequestContext, parameters: Optional[dict[str, Any]] = None, producer: Optional[AnswerProducer] = None) -> AnswerOutcome | Clarification

Parameter Type Default Description
question str The user's question.
request_context RequestContext The trusted request context.
parameters Optional[dict[str, Any]] None Optional explicit pattern parameters.
producer Optional[AnswerProducer] None

Returns: AnswerOutcome | Clarification — class:AnswerOutcome, or a typed :class:Clarification.

Raises:

  • ServiceUnavailable — When the outcome could not be audited.

Method ContractsAnswerService.stream_answer

Stream an answer, buffering everything substantive.

Nothing is yielded until authorization, verification and audit have all succeeded — a raw model draft can never reach a transport.

stream_answer(question: str, *, request_context: RequestContext, producer: Optional[AnswerProducer] = None) -> AsyncIterator[str]

Parameter Type Default Description
question str
request_context RequestContext
producer Optional[AnswerProducer] None

Returns: AsyncIterator[str]

Method ContractsAnswerService.retire_answer

Retire an answer and suppress its evidence.

retire_answer(answer_id: str, *, request_context: RequestContext, reason: str) -> AnswerRecord

Parameter Type Default Description
answer_id str The audited answer to retire.
request_context RequestContext Trusted context of an authenticated owner.
reason str Why it is being retired (recorded).

Returns: AnswerRecord — The retired :class:AnswerRecord.

Raises:

  • AuthorizationDenied — Without the owner role.
  • ConfirmationRequired — Without transport confirmation.

Method ContractsAnswerService.verify_card

Verify/correct card fields on behalf of an authenticated owner.

verify_card(contract_id: str, fields: Optional[dict[str, Any]] = None, *, request_context: RequestContext, expected_revision: Optional[int] = None) -> Any

Parameter Type Default Description
contract_id str
fields Optional[dict[str, Any]] None
request_context RequestContext
expected_revision Optional[int] None

Returns: Any

Raises:

  • AuthorizationDenied / ConfirmationRequired — As above.
  • ServiceUnavailable — When no library is configured.

Method ContractsAnswerService.merge_parties

Merge two party identities on behalf of an authenticated owner.

merge_parties(keep_party_id: str, merge_party_id: str, *, request_context: RequestContext) -> Any

Parameter Type Default Description
keep_party_id str
merge_party_id str
request_context RequestContext

Returns: Any

Attribute MAX_DOSSIER_CARDS

Attribute MAX_HANDOFF_CLAUSES

Class ServiceUnavailable

A dependency the release path requires was unavailable.

Raised — rather than answering — when the audit store cannot record the outcome, because an unaudited answer must never be released.

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