Skip to content

API Reference parrot.knowledge.contracts.datasource

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

parrot.knowledge.contracts.datasource

View source

Catalog-backed ontology datasource for contract cards (FEAT-539 M5).

:class:ContractCardDataSource projects the authoritative Postgres catalog into the five contracts ontology entities. It is registered with DataSourceFactory under the name contractcard (the source: of every contracts entity in the domain YAML) and receives its tenant-bound catalog through the source configuration — never through a call argument.

Routing note (spec §2): the requested field sets overlap — Person and Party both carry party_id/name, Obligation carries contract_id — so entity inference tests the key markers in a fixed order: obligation_id, person_id, party_id, contract_id, standard_id. A request that is not a subset of the matched entity's fields is rejected rather than silently projected.

Class ContractCardDataSource

Project the contract catalog into ontology entity records.

Parameter Type Default Description
name str SOURCE_NAME Source name (contractcard).
config Optional[dict[str, Any]] None Must carry catalog: a tenant-bound :class:~parrot.knowledge.contracts.catalog.ContractCatalogStore. An include_inactive flag (default False) is also honoured.

Attributes:

Attribute Type Description
catalog ContractCatalogStore
include_inactive bool

Method ContractCardDataSource.infer_entity

Infer which entity a field request addresses.

infer_entity(fields: Optional[list[str]]) -> str

Parameter Type Default Description
fields Optional[list[str]] Requested field names, or None for the Contract projection (the primary entity).

Returns: str — The entity name.

Raises:

  • UnknownFieldRequest — When no key marker is present, or the request is not a subset of the matched entity's fields (an ambiguous mix of two entities).

Method ContractCardDataSource.records_for

Project one entity's records.

records_for(entity: str, *, filters: Optional[dict[str, Any]] = None) -> list[dict[str, Any]]

Parameter Type Default Description
entity str One of the five contracts entities.
filters Optional[dict[str, Any]] None Standalone selection filters.

Returns: list[dict[str, Any]] — Deterministically ordered plain dicts.

Raises:

  • UnknownFieldRequest — On an unknown entity or filter.

Method ContractCardDataSource.snapshot

Return a complete, prevalidated snapshot of every entity.

The graph loader preflights this before mutating anything, so an extraction failure can never be mistaken for "everything was deleted".

snapshot(*, filters: Optional[dict[str, Any]] = None) -> dict[str, list[dict[str, Any]]]

Parameter Type Default Description
filters Optional[dict[str, Any]] None Optional standalone filters (never used by the full-catalog refresh path).

Returns: dict[str, list[dict[str, Any]]] — entity name -> records for all five entities.

Method ContractCardDataSource.extract

Extract one entity's records for the ontology refresh pipeline.

Extraction failures propagate: an unreachable catalog must never be reported as a successful empty snapshot, because the generic diff would soft-delete every existing node.

extract(fields: Optional[list[str]] = None, filters: Optional[dict[str, Any]] = None) -> 'ExtractionResult'

Parameter Type Default Description
fields Optional[list[str]] None The entity's property names (the pipeline passes these).
filters Optional[dict[str, Any]] None Optional standalone filters.

Returns: 'ExtractionResult' — class:ExtractionResult with plain-dict records.

Raises:

  • UnknownFieldRequest — On an unrecognised/ambiguous field request.

Method ContractCardDataSource.list_fields

Return every field any contracts entity can supply.

list_fields() -> list[str]

Returns: list[str]

Attribute ENTITY_FIELDS

Type: dict[str, frozenset[str]]

Attribute ENTITY_ROUTING_ORDER

Type: tuple[tuple[str, str], ...]

Attribute SOURCE_NAME

Class UnknownFieldRequest

The requested field set matches no contracts entity unambiguously.

Function register

Register this datasource under contractcard.

Idempotent; a no-op when ai-parrot-loaders is not installed.

register() -> None

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