""" models.py — Pydantic v2 output models for uk-due-diligence-mcp tools. Wrapper + item models returned by this server's tools. Each domain has its own section. Every Field has a description so the auto-generated outputSchema advertised by FastMCP is self-documenting. Added as part of the Phase 2 return-type migration: tools now return `-> PydanticModel` directly instead of `-> str + json.dumps(...)`. """ from __future__ import annotations from typing import Any from pydantic import BaseModel, ConfigDict, Field BASE_CFG = ConfigDict(str_strip_whitespace=True) # ============================================================================= # Companies House # ============================================================================= class CompanySearchItem(BaseModel): """A single entry in a Companies House search result.""" model_config = BASE_CFG company_number: str | None = Field( None, description="Companies House company number (e.g. '12345678')." ) title: str | None = Field( None, description="Registered company name." ) company_status: str | None = Field( None, description="Company status (e.g. 'active', 'dissolved', 'liquidation').", ) company_type: str | None = Field( None, description="Companies House company type code (e.g. 'ltd', 'plc', 'llp').", ) date_of_creation: str | None = Field( None, description="Incorporation date in ISO format (YYYY-MM-DD)." ) sic_codes: list[str] = Field( default_factory=list, description="Standard Industrial Classification codes associated with the company.", ) address: dict[str, Any] = Field( default_factory=dict, description="Registered office address as returned by the Companies House API.", ) description: str | None = Field( None, description="Short upstream description (usually number + status + creation date).", ) class CompanySearchResult(BaseModel): """Paginated result of a Companies House company search.""" model_config = BASE_CFG query: str = Field(..., description="The query string that was searched.") total_results: int = Field( ..., description=( "Companies House's total for the query BEFORE any status/type filter " "(same as upstream_total, kept for compatibility). Not a count of " "filtered matches." ), ) upstream_total: int = Field( ..., description=( "Total results Companies House reports for the query text alone. " "/search/companies cannot filter by status or type, so this is unfiltered." ), ) start_index: int = Field( ..., description="Number of results skipped before this page (upstream start_index).", ) items_per_page: int = Field( ..., description="Page size requested from the API for this call." ) returned: int = Field( ..., description="Number of items actually returned on this page." ) filtered_returned: int = Field( ..., description=( "Number of returned items that passed filters_applied (equal to " "`returned`; every returned item satisfies every applied filter)." ), ) filters_applied: dict[str, str] = Field( default_factory=dict, description=( "Filters this server applied to the results, e.g. " "{'company_status': 'active'}. Empty when none were requested. " "Companies House ignores status/type on this endpoint, so the server " "filters each upstream page itself." ), ) upstream_scanned: int = Field( ..., description="Upstream search results examined to build this page.", ) is_partial: bool = Field( False, description=( "True when filtering stopped at the per-call cap of 500 scanned results before finding " "items_per_page matches and before reaching the end of the upstream " "results. Fewer items does NOT mean no more matches exist: re-call " "with start_index=next_start_index to keep scanning." ), ) partial_reason: str | None = Field( None, description="Why the result is partial, when is_partial is true." ) next_start_index: int | None = Field( None, description=( "Upstream offset to pass as start_index for the next page, or null " "when the upstream results are exhausted. With filters this is NOT " "start_index+items_per_page, because non-matching results are skipped." ), ) has_more: bool = Field( ..., description=( "True if upstream results remain beyond this page. Re-call with " "start_index=next_start_index to fetch the next page." ), ) items: list[CompanySearchItem] = Field( default_factory=list, description=( "Matching companies. Use the `company_number` field to call " "company_profile, company_officers, or company_psc for full detail." ), ) class CompanyAccountsSummary(BaseModel): """Summary of a company's accounts filing status.""" model_config = BASE_CFG overdue: bool | None = Field( None, description=( "True if the accounts are past due at Companies House, false if " "Companies House says they are not. Null when Companies House " "returned no overdue flag (e.g. a registered overseas entity, or a " "missing block): unknown, NOT an all-clear." ), ) last_accounts_made_up_to: str | None = Field( None, description="ISO date the most recent filed accounts were made up to.", ) next_due: str | None = Field( None, description="ISO date the next set of accounts is due." ) class CompanyConfirmationStatementSummary(BaseModel): """Summary of a company's confirmation statement filing status.""" model_config = BASE_CFG overdue: bool | None = Field( None, description=( "True if the confirmation statement is past due at Companies House, false if " "Companies House says it is not. Null when Companies House " "returned no overdue flag (e.g. a registered overseas entity, or a " "missing block): unknown, NOT an all-clear." ), ) next_due: str | None = Field( None, description="ISO date the next confirmation statement is due." ) class CompanyProfile(BaseModel): """Full Companies House profile for a single company number.""" model_config = BASE_CFG company_number: str = Field(..., description="Companies House company number.") company_name: str | None = Field(None, description="Registered company name.") company_status: str | None = Field( None, description="Current status (active, dissolved, in liquidation, etc.)." ) company_type: str | None = Field( None, description="Companies House company type code." ) date_of_creation: str | None = Field( None, description="Incorporation date (ISO YYYY-MM-DD)." ) sic_codes: list[str] = Field( default_factory=list, description="Standard Industrial Classification codes.", ) registered_office_address: dict[str, Any] = Field( default_factory=dict, description="Registered office address as returned by Companies House.", ) has_charges: bool | None = Field( None, description=( "True if the company has at least one outstanding or " "part-satisfied charge (secured debt) — not yet fully " "discharged. False if every charge on record is fully " "satisfied, or there are none. Null if the charges check " "could not be completed, or if a charge was returned with an " "unrecognized status that can't be confidently classified. " "Use company_charges for the full charge-by-charge detail." ), ) accounts: CompanyAccountsSummary = Field( default_factory=CompanyAccountsSummary, description="Accounts filing status and due dates.", ) confirmation_statement: CompanyConfirmationStatementSummary = Field( default_factory=CompanyConfirmationStatementSummary, description="Confirmation statement filing status and next due date.", ) class CompanyOfficer(BaseModel): """A single officer (director, secretary, etc.) of a company.""" model_config = BASE_CFG name: str | None = Field(None, description="Officer name as recorded at CH.") officer_role: str | None = Field( None, description="Officer role (e.g. 'director', 'secretary', 'llp-member').", ) appointed_on: str | None = Field( None, description="Date of appointment (ISO YYYY-MM-DD)." ) resigned_on: str | None = Field( None, description="Date of resignation if resigned, otherwise null.", ) nationality: str | None = Field(None, description="Declared nationality.") country_of_residence: str | None = Field( None, description="Declared country of residence." ) occupation: str | None = Field(None, description="Declared occupation.") date_of_birth: dict[str, Any] = Field( default_factory=dict, description="Partial date of birth (month/year) as returned by CH.", ) officer_id: str | None = Field( None, description=( "Companies House officer ID, extracted from links.officer.appointments. " "Pass to officer_appointments to discover this person's full appointment " "history across companies, including dissolved or insolvent ones." ), ) appointment_count: int | None = Field( None, description=( "Total number of other active appointments held by this officer, or null " "if unavailable. The Companies House officer list endpoint does not include " "this count; a separate per-officer call is required to populate it." ), ) address: dict[str, Any] = Field( default_factory=dict, description="Officer correspondence address.", ) links: dict[str, Any] = Field( default_factory=dict, description="Upstream relational links (e.g. officer profile URL).", ) class CompanyOfficersResult(BaseModel): """List of officers for a given company.""" model_config = BASE_CFG company_number: str = Field(..., description="Companies House company number.") include_resigned: bool = Field( ..., description="Whether resigned officers were included in this result.", ) total: int = Field( ..., description="Total officers returned (filtered by include_resigned)." ) high_appointment_count_flag: int | None = Field( None, description=( "Number of active officers with 10+ total appointments, or null " "if appointment counts were not fetched. Non-zero values are a " "nominee/phoenix director risk signal." ), ) officers: list[CompanyOfficer] = Field( default_factory=list, description="Officer records.", ) class OfficerAppointment(BaseModel): """A single appointment from an officer's full appointment history.""" model_config = BASE_CFG company_number: str | None = Field( None, description="Companies House company number for this appointment." ) company_name: str | None = Field( None, description="Company name as recorded at CH for this appointment." ) company_status: str | None = Field( None, description=( "Company status at the time of lookup (e.g. 'active', 'liquidation', " "'dissolved'), as returned upstream. Companies House does not " "auto-resign directors on insolvency, so resigned_on may be null " "even when company_status shows the company is no longer trading — " "check company_status, not just resigned_on, to assess a relationship." ), ) officer_role: str | None = Field( None, description="Officer role at this company (e.g. 'director', 'secretary')." ) appointed_on: str | None = Field( None, description="Date of appointment (ISO YYYY-MM-DD)." ) resigned_on: str | None = Field( None, description="Date of resignation, or null if not resigned." ) nationality: str | None = Field(None, description="Declared nationality.") country_of_residence: str | None = Field( None, description="Declared country of residence." ) address: dict[str, Any] = Field( default_factory=dict, description="Officer correspondence address for this appointment." ) links: dict[str, Any] = Field( default_factory=dict, description="Upstream relational links, e.g. links.company = '/company/{number}'.", ) class OfficerAppointmentsResult(BaseModel): """A person's full appointment history across companies, by officer ID.""" model_config = BASE_CFG officer_id: str = Field(..., description="Companies House officer ID.") name: str | None = Field(None, description="Officer name as recorded at CH.") date_of_birth: dict[str, Any] = Field( default_factory=dict, description="Partial date of birth (month/year), or empty if not disclosed upstream.", ) total: int = Field(..., description="Total appointments returned.") active_count: int | None = Field( None, description=( "Upstream count of appointments Companies House categorizes as " "'active' — this reflects the officer's own appointment/resignation " "state at that company, NOT whether the company itself is " "currently trading. An appointment at a company in liquidation or " "administration still counts as active here if the officer was " "never formally resigned. Check each appointment's own " "company_status field for the company's actual status. Null if " "not provided upstream." ), ) resigned_count: int | None = Field( None, description="Upstream count of resigned appointments, or null if not provided." ) inactive_count: int | None = Field( None, description=( "Upstream count of appointments Companies House categorizes as " "'inactive', passed through as-is. Exact categorization semantics " "have not been independently verified against per-appointment " "data — treat as an unverified upstream fact, not a derived signal, " "or null if not provided." ), ) appointments: list[OfficerAppointment] = Field( default_factory=list, description="Every appointment, current and historic." ) class CompanyPSCEntry(BaseModel): """A single Person with Significant Control record.""" model_config = BASE_CFG kind: str | None = Field( None, description=( "Upstream 'kind' (e.g. 'individual-person-with-significant-control', " "'corporate-entity-person-with-significant-control')." ), ) name: str | None = Field(None, description="PSC name (individual or entity).") notified_on: str | None = Field( None, description="Date notified as a PSC (ISO YYYY-MM-DD)." ) ceased_on: str | None = Field( None, description="Date PSC status ceased, if applicable.", ) nationality: str | None = Field( None, description="Declared nationality for individual PSCs." ) country_of_residence: str | None = Field( None, description="Declared country of residence for individual PSCs.", ) date_of_birth: dict[str, Any] = Field( default_factory=dict, description="Partial date of birth (month/year) for individual PSCs as returned by CH.", ) natures_of_control: list[str] = Field( default_factory=list, description=( "List of 'nature of control' descriptors (e.g. " "'ownership-of-shares-75-to-100-percent'). Individual entries may " "be truncated to 300 characters each." ), ) identification: dict[str, Any] = Field( default_factory=dict, description=( "Identification block for corporate PSCs: place_registered, " "registration_number, country_registered, legal_authority, etc." ), ) address: dict[str, Any] = Field( default_factory=dict, description="PSC correspondence address.", ) class CompanyPSCResult(BaseModel): """List of Persons with Significant Control for a company.""" model_config = BASE_CFG company_number: str = Field(..., description="Companies House company number.") total: int = Field( ..., description="Total PSC entries returned for this company." ) overseas_corporate_psc_flag: int = Field( 0, description=( "Number of corporate PSCs registered outside the UK. Non-zero " "values indicate an offshore beneficial ownership chain." ), ) psc: list[CompanyPSCEntry] = Field( default_factory=list, description="Persons with Significant Control records.", ) note: str | None = Field( None, description=( "Explanatory note when total=0. Typical for widely-held listed PLCs " "where no single person or entity holds 25%+ of shares or voting rights." ), ) class ChargeParticulars(BaseModel): """What a charge covers — free text and/or boolean flags. Field presence varies by charge age/type: pre-2006 debentures often carry only type/description with no boolean flags; MR01-style charges (2013+) often carry only the boolean flags with no free text. Every field is optional — do not assume any subset is always present. """ model_config = BASE_CFG type: str | None = Field( None, description="Particulars entry type as returned by CH (e.g. 'brief-description', 'short-particulars')." ) description: str | None = Field( None, description="Free-text description of what the charge covers, where filed." ) contains_floating_charge: bool | None = Field( None, description="True if the charge includes a floating charge." ) contains_fixed_charge: bool | None = Field( None, description="True if the charge includes a fixed charge." ) floating_charge_covers_all: bool | None = Field( None, description="True if the floating charge covers the whole undertaking/all assets." ) contains_negative_pledge: bool | None = Field( None, description="True if the charge includes a negative pledge (restricting further charges)." ) class ChargeSecuredDetails(BaseModel): """Free-text 'amount secured' description. Seen only on older/pre-2006 charge filings — absent on newer MR01-style charges, which express scope entirely through ChargeParticulars' boolean flags instead. Optional, not assume-present. """ model_config = BASE_CFG type: str | None = Field( None, description="Secured-details entry type as returned by CH (e.g. 'amount-secured')." ) description: str | None = Field( None, description="Free-text description of the amount/obligation secured." ) class ChargeClassification(BaseModel): """Charge type classification (e.g. 'A registered charge', 'Debenture').""" model_config = BASE_CFG type: str | None = Field( None, description="Classification type as returned by CH (e.g. 'charge-description')." ) description: str | None = Field( None, description="Human-readable charge type (e.g. 'A registered charge', 'Debenture')." ) class ChargePersonEntitled(BaseModel): """A secured party named on a charge.""" model_config = BASE_CFG name: str | None = Field( None, description="Name of the person or entity entitled under this charge, as filed." ) class ChargeTransaction(BaseModel): """A filing event against a charge (creation, satisfaction, etc.).""" model_config = BASE_CFG filing_type: str | None = Field( None, description="Filing type (e.g. 'create-charge-with-deed', 'charge-satisfaction')." ) delivered_on: str | None = Field( None, description="Date this filing was delivered (ISO YYYY-MM-DD)." ) links: dict[str, Any] = Field( default_factory=dict, description="Upstream relational links, e.g. links.filing = filing-history path.", ) class CompanyCharge(BaseModel): """A single Companies House charge (secured debt registration). Satisfaction is represented via satisfied_on and a transactions[] entry with filing_type == 'charge-satisfaction' — there is no separate 'release' concept upstream, so none is invented here. """ model_config = BASE_CFG charge_number: int = Field( ..., description="Sequential charge number for this company. Always present, unlike charge_code." ) charge_code: str | None = Field( None, description=( "Human-readable charge ID (e.g. '063334690005'). Absent on some " "older charges (e.g. pre-2006 debentures) — use charge_number " "as the reliable identifier." ), ) status: str | None = Field( None, description="Charge status as returned upstream (e.g. 'outstanding', 'part-satisfied', 'fully-satisfied').", ) classification: ChargeClassification | None = Field( None, description="Charge type classification." ) created_on: str | None = Field( None, description="Date the charge was created (ISO YYYY-MM-DD)." ) delivered_on: str | None = Field( None, description="Date the charge was delivered/registered (ISO YYYY-MM-DD)." ) satisfied_on: str | None = Field( None, description="Date the charge was satisfied, or null if still live." ) particulars: ChargeParticulars | None = Field( None, description="What the charge covers — free text and/or boolean flags, depending on charge age/type." ) secured_details: ChargeSecuredDetails | None = Field( None, description="Free-text amount-secured description. Present only on some older charges." ) persons_entitled: list[ChargePersonEntitled] = Field( default_factory=list, description="Secured parties named on this charge." ) transactions: list[ChargeTransaction] = Field( default_factory=list, description=( "Filing events against this charge — creation, satisfaction, etc. " "Satisfaction is represented here (filing_type='charge-satisfaction') " "and via satisfied_on, not a separate 'release' concept." ), ) links: dict[str, Any] = Field( default_factory=dict, description="Upstream relational links, e.g. links.self = charge record path." ) class CompanyChargesResult(BaseModel): """Complete charge history for a company.""" model_config = BASE_CFG company_number: str = Field(..., description="Companies House company number.") total_count: int = Field(..., description="Total charges returned.") unfiltered_count: int | None = Field( None, description="Upstream unfiltered charge count, or null if not provided." ) satisfied_count: int | None = Field( None, description="Upstream count of satisfied charges, or null if not provided." ) part_satisfied_count: int | None = Field( None, description="Upstream count of part-satisfied charges, or null if not provided." ) charges: list[CompanyCharge] = Field( default_factory=list, description="Every charge, current and historic." ) class CompanyFiling(BaseModel): """A single Companies House filing-history entry. resolutions/associated_filings/annotations are nested filing-like dicts (their own category/type/description/description_values) but carry no transaction_id or links of their own — not independently document-retrievable — so they are passed through raw rather than modeled. subcategory is usually a string but has been observed as a list of strings upstream (e.g. ["compulsory", "court-order"]); preserved as whichever shape upstream sent, not normalized. """ model_config = BASE_CFG transaction_id: str = Field( ..., description="Companies House filing transaction ID. Path segment in links.self." ) type: str = Field( ..., description="CH filing form code (e.g. 'AA', 'CS01', 'MR04', 'CH01', 'RESOLUTIONS')." ) date: str | None = Field(None, description="Filing/delivery date (ISO YYYY-MM-DD).") action_date: str | None = Field( None, description=( "Effective date of the underlying event, where distinct from the " "filing date (e.g. a change filed weeks after it took effect)." ), ) category: str | None = Field( None, description="Filing category (e.g. 'accounts', 'mortgage', 'officers', 'insolvency', 'resolution').", ) subcategory: str | list[str] | None = Field( None, description="Filing subcategory as returned upstream — usually a string, occasionally a list of strings.", ) description: str | None = Field( None, description="Filing description slug as returned by CH (e.g. 'incorporation-company'), not prose." ) description_values: dict[str, Any] = Field( default_factory=dict, description="Free-form values referenced by the description slug. Keys vary entirely by filing type.", ) pages: int | None = Field( None, description="Page count of the underlying filed document (not filing-history pagination)." ) paper_filed: bool | None = Field(None, description="True if filed on paper rather than electronically.") barcode: str | None = Field(None, description="CH barcode for this filing. Absent on many older filings.") resolutions: list[dict[str, Any]] = Field( default_factory=list, description="Nested resolution filings, where this entry is a RESOLUTIONS bundle." ) associated_filings: list[dict[str, Any]] = Field( default_factory=list, description="Other filings bundled with this one (e.g. a same-day statement of capital)." ) annotations: list[dict[str, Any]] = Field( default_factory=list, description="CH clarification notes attached to this filing after the fact." ) links: dict[str, Any] = Field( default_factory=dict, description=( "Upstream relational links. links.self is always present; " "links.document_metadata (Document API URL) is present on most " "but not all filings — absent on some pre-2008 filings." ), ) class CompanyFilingHistoryResult(BaseModel): """One page of Companies House filing-history results for a company. Not an auto-fetch-all collection like officers/PSC/charges — a company's filing history is unbounded in practice (a long-lived PLC can carry thousands of filings, multiple megabytes serialized), so pagination is exposed to the caller rather than hidden. Re-call with start_index=start_index+returned while has_more is true. """ model_config = BASE_CFG company_number: str = Field(..., description="Companies House company number.") category: str | None = Field( None, description="The category filter applied to this query, or null if unfiltered." ) filing_history_status: str | None = Field( None, description="Upstream filing-history status (e.g. 'filing-history-available')." ) total_count: int = Field(..., description="Total filings matching this query (across all pages).") start_index: int = Field(..., description="Pagination offset used for this page.") items_per_page: int = Field(..., description="Page size actually used (CH caps at 100 regardless of a higher request).") returned: int = Field(..., description="Filings returned on this page.") has_more: bool = Field(..., description="True if start_index + returned < total_count.") note: str | None = Field( None, description=( "Advisory note, e.g. suggesting a category filter when total_count is " "large and no category was applied. Informational only — never a truncation." ), ) filings: list[CompanyFiling] = Field(default_factory=list, description="Filings on this page.") class CompanyFilingDocumentResult(BaseModel): """Structured summary of a single Companies House filed document. This is metadata only — the actual bytes are never embedded here or anywhere in a tool result. resource_uri is a company-document:// MCP resource URI; fetch it via resources/read to get the authoritative binary. category uses the Document API's own vocabulary (e.g. 'mortgages', 'new-companies', 'liquidations'), which is a DIFFERENT set of strings from CompanyFiling.category on the same filing (e.g. 'mortgage', 'incorporation', 'insolvency') — confirmed live, not assumed to align. """ model_config = BASE_CFG document_id: str = Field(..., description="Companies House document ID, extracted from document_metadata_url.") company_number: str | None = Field(None, description="Company number this document belongs to.") category: str | None = Field( None, description="Document API category (its own vocabulary — see class docstring)." ) pages: int | None = Field(None, description="Page count of the document.") filename: str | None = Field( None, description="Filename as recorded by CH, if any — often empty; not reliable to assume present." ) created_at: str | None = Field(None, description="When this document record was created (ISO 8601 timestamp).") mime_type: str = Field(..., description="The resolved MIME type this result refers to (e.g. 'application/pdf').") content_length: int | None = Field(None, description="Declared byte size for mime_type, if known.") resource_uri: str = Field( ..., description="company-document:// MCP resource URI — read it to fetch the actual binary." ) note: str | None = Field( None, description="Advisory note, e.g. flagging an unusually large document. Informational only, never blocking.", ) # ============================================================================= # Disqualified directors # ============================================================================= class DisqualifiedSearchItem(BaseModel): """A single hit in a disqualified officers search.""" model_config = BASE_CFG officer_id: str | None = Field( None, description=( "Companies House officer ID extracted from the self link. Pass to " "disqualified_profile for the full disqualification record." ), ) title: str | None = Field( None, description="Display title (typically the officer's name)." ) date_of_birth: str | None = Field( None, description="Date of birth as returned by the search API." ) snippet: str | None = Field( None, description="Upstream match snippet highlighting query terms." ) address: dict[str, Any] = Field( default_factory=dict, description="Last known address of the disqualified officer.", ) links: dict[str, Any] = Field( default_factory=dict, description="Upstream relational links (self, etc.).", ) class DisqualifiedSearchResult(BaseModel): """Paginated disqualified officers search result.""" model_config = BASE_CFG query: str = Field(..., description="Search query applied.") total_results: int = Field( ..., description="Total matching records upstream at Companies House." ) start_index: int = Field(..., description="Pagination offset for this page.") items_per_page: int = Field(..., description="Page size requested.") returned: int = Field(..., description="Items actually returned on this page.") has_more: bool = Field( ..., description=( "True if more items may exist beyond this page. Re-call with " "start_index=start_index+items_per_page to continue." ), ) items: list[DisqualifiedSearchItem] = Field( default_factory=list, description="Matching disqualified officer records.", ) class DisqualificationOrder(BaseModel): """A single disqualification order attached to a disqualified director.""" model_config = BASE_CFG disqualified_from: str | None = Field( None, description="Start date of the disqualification period." ) disqualified_until: str | None = Field( None, description="End date of the disqualification period." ) reason: dict[str, Any] = Field( default_factory=dict, description=( "Reason block as returned upstream: act, section, " "description_identifier, article, etc." ), ) company_names: list[str] = Field( default_factory=list, description=( "Companies associated with this disqualification. The list may be " "truncated to 20 entries." ), ) company_names_truncated: bool = Field( False, description="True if the company_names list was truncated to max_companies.", ) company_names_total: int = Field( 0, description=( "Total number of companies originally attached to this order before " "truncation (may equal `len(company_names)`)." ), ) address: dict[str, Any] = Field( default_factory=dict, description="Address on record at the time of the order.", ) case_identifier: str | None = Field( None, description="Upstream case_identifier, when provided.", ) heard_on: str | None = Field( None, description="Date the order was heard, when provided." ) last_variation: dict[str, Any] = Field( default_factory=dict, description="Details of the last variation of this order, if any.", ) undertaken_on: str | None = Field( None, description="Date the undertaking was given, when provided." ) class DisqualifiedProfile(BaseModel): """Full disqualification record for a disqualified officer.""" model_config = BASE_CFG officer_id: str = Field(..., description="Companies House officer ID looked up.") officer_kind: str = Field( ..., description=( "Which CH endpoint returned the record: 'natural' (individual) or " "'corporate' (legal entity)." ), ) name: str | None = Field(None, description="Officer name.") forename: str | None = Field(None, description="Given name, if split upstream.") surname: str | None = Field(None, description="Family name, if split upstream.") date_of_birth: str | None = Field(None, description="Date of birth on record.") nationality: str | None = Field(None, description="Declared nationality.") disqualifications: list[DisqualificationOrder] = Field( default_factory=list, description="All disqualification orders attached to this officer.", ) # ============================================================================= # Charity Commission # ============================================================================= class CharitySearchItem(BaseModel): """A single hit in a Charity Commission name search.""" model_config = BASE_CFG charity_number: str | None = Field( None, description=( "Charity Commission registration number. Pass to charity_profile " "for the full record." ), ) charity_name: str | None = Field(None, description="Registered charity name.") reg_status: str | None = Field( None, description=( "Registration status code as returned upstream: 'R' registered, " "'RM' removed." ), ) reg_status_label: str | None = Field( None, description="Human-readable registration status ('Registered', 'Removed').", ) date_of_registration: str | None = Field( None, description="Date of first registration (ISO YYYY-MM-DD)." ) class CharitySearchResult(BaseModel): """Paginated result of a Charity Commission name search.""" model_config = BASE_CFG query: str = Field(..., description="Search term applied.") total: int = Field(..., description="Total matches returned by upstream.") offset: int = Field( ..., description="Number of items skipped before this page (client-side)." ) limit: int = Field(..., description="Max items requested for this page.") returned: int = Field(..., description="Items actually returned on this page.") has_more: bool = Field( ..., description=( "True if more items may exist beyond this page. Re-call with " "offset=offset+returned to continue." ), ) charities: list[CharitySearchItem] = Field( default_factory=list, description="Matching charity records.", ) class CharityTrustee(BaseModel): """A single charity trustee record.""" model_config = BASE_CFG trustee_name: str | None = Field(None, description="Trustee name.") class CharityClassification(BaseModel): """Who/What/Where classification descriptor.""" model_config = BASE_CFG classification_type: str | None = Field( None, description="Classification axis: 'What', 'Who', or 'Where'.", ) classification_desc: str | None = Field( None, description="Classification description text." ) class CharityProfile(BaseModel): """Full Charity Commission profile for a single charity.""" model_config = BASE_CFG charity_number: str = Field(..., description="Charity registration number.") charity_name: str | None = Field(None, description="Registered charity name.") reg_status: str | None = Field( None, description="Registration status code ('R', 'RM')." ) reg_status_label: str | None = Field( None, description="Human-readable registration status." ) charity_type: str | None = Field(None, description="Charity type.") charity_co_reg_number: str | None = Field( None, description=( "Companies House number for charities also registered as companies " "(Charitable Incorporated Organisations, etc.)." ), ) date_of_registration: str | None = Field( None, description="Date of first registration." ) address: str | None = Field( None, description="Registered address of the charity (joined address lines).", ) latest_income: float | None = Field( None, description="Latest filed annual income in GBP." ) latest_expenditure: float | None = Field( None, description="Latest filed annual expenditure in GBP." ) insolvent: bool = Field( False, description="True if the charity is flagged as insolvent." ) in_administration: bool = Field( False, description="True if the charity is in administration." ) trustee_names: list[CharityTrustee] = Field( default_factory=list, description=( "Trustees on record. Truncated to 30 entries." ), ) trustee_names_truncated: bool = Field( False, description="True if the trustee list was truncated." ) trustee_names_total: int = Field( 0, description="Total trustees upstream before truncation." ) who_what_where: list[CharityClassification] = Field( default_factory=list, description=( "Who/What/Where classification entries. The list may be truncated " "truncated to 50 entries." ), ) who_what_where_truncated: bool = Field( False, description="True if the classification list was truncated.", ) who_what_where_total: int = Field( 0, description="Total classification entries upstream before truncation.", ) countries_of_operation: list[str] = Field( default_factory=list, description="Countries the charity operates in (capped at 10 upstream).", ) # ============================================================================= # Land Registry # ============================================================================= class LandTitleTransaction(BaseModel): """A single Price Paid transaction for a property.""" model_config = BASE_CFG price_paid: int | None = Field( None, description="Sale price in GBP (integer pounds)." ) transaction_date: str | None = Field( None, description="Transaction date (ISO YYYY-MM-DD)." ) postcode: str | None = Field(None, description="Property postcode.") paon: str | None = Field( None, description="Primary addressable object name (house number or name).", ) saon: str | None = Field( None, description="Secondary addressable object name (flat/unit identifier).", ) street: str | None = Field(None, description="Street name.") town: str | None = Field(None, description="Town/city.") county: str | None = Field(None, description="County.") property_type: str | None = Field( None, description=( "Property type label extracted from the HMLR URI " "(e.g. 'Terraced', 'Semi Detached', 'Flat')." ), ) estate_type: str | None = Field( None, description="Tenure / estate type label (e.g. 'Freehold', 'Leasehold').", ) class LandTitleSearchResult(BaseModel): """HMLR Price Paid Index search result for a given postcode.""" model_config = BASE_CFG postcode: str = Field( ..., description="Normalised UK postcode extracted from the input.", ) total: int = Field( ..., description=( "Number of Price Paid transactions returned. Capped at 10 by the " "upstream SPARQL query." ), ) transactions: list[LandTitleTransaction] = Field( default_factory=list, description=( "Recent Price Paid transactions for the postcode, sorted newest first." ), ) # ============================================================================= # The Gazette # ============================================================================= class GazetteNotice(BaseModel): """A single corporate insolvency notice from The Gazette.""" model_config = BASE_CFG notice_id: str | None = Field( None, description="Gazette notice URI (e.g. 'https://www.thegazette.co.uk/id/notice/5122793')." ) notice_numeric_id: str | None = Field( None, description=( "Numeric notice ID. Read full notice content via the " "notice://{notice_numeric_id} resource." ), ) notice_code: str | None = Field( None, description=( "Gazette notice code (e.g. '2450' petition to wind up a company, " "'2452' winding-up order for a company)." ), ) notice_type: str | None = Field( None, description="Human-readable notice type label (e.g. 'Winding-Up Order').", ) severity: int = Field( 0, description=( "Internal severity score 0-10. Higher = more serious (10 = " "winding-up order, 9 = administration/receiver/liquidator appointment, " "0 = informational or unclassified)." ), ) date: str | None = Field( None, description="Publication date (ISO YYYY-MM-DD).", ) title: str | None = Field(None, description="Notice title.") content: str | None = Field( None, description=( "Brief notice excerpt from the search feed (HTML stripped). " "For full legal wording read notice://{notice_numeric_id}." ), ) class GazetteNoticeResult(BaseModel): """One Gazette notice: its full wording plus the labelled fields it carries. Read from the notice's XHTML+RDFa page (GET /notice/{id}, Accept: application/xml). A field the notice does not carry is null (unknown), never an empty string. """ model_config = BASE_CFG notice_id: str = Field( ..., description=( "The Gazette notice ID as requested: numeric (e.g. '4420724') or legacy " "(e.g. 'L-57793-2040')." ), ) notice_url: str = Field( ..., description="The notice's page on The Gazette (https://www.thegazette.co.uk/notice/{id})." ) title: str | None = Field( None, description=( "The notice's title. Modern notices use the company name; legacy notices " "use the notice type (e.g. 'Winding-Up Orders')." ), ) notice_code: str | None = Field( None, description="Gazette notice code (e.g. '2410' appointment of administrators, '2452' winding-up order).", ) notice_type: str | None = Field( None, description="The Gazette's own notice type label (e.g. 'Appointment of Administrators').", ) category: str | None = Field( None, description="The Gazette's category label (e.g. 'Corporate Insolvency')." ) publication_date: str | None = Field( None, description="Publication date (ISO YYYY-MM-DD); null when the notice states none." ) company_number: str | None = Field( None, description=( "Companies House number from the notice's structured data. Null means the " "notice carries no structured number (common on legacy notices), not that it " "is about a different company: check the text. Never parsed from the text." ), ) company_name: str | None = Field( None, description="Company name from the notice's structured data; null when absent." ) previous_company_name: str | None = Field( None, description="Previous company name from the notice's structured data; null when absent.", ) text: str = Field( ..., description=( "The full notice wording, as published, with whitespace collapsed. Read it " "before drawing any legal conclusion from the notice type." ), ) class GazetteInsolvencyResult(BaseModel): """Aggregated Gazette insolvency notice search result.""" model_config = BASE_CFG entity_name: str = Field(..., description="Entity name that was searched.") notice_type_filter: str | None = Field( None, description="Notice code filter applied, or null if all codes searched.", ) start_date: str | None = Field( None, description="Lower bound of the date range filter, if any." ) end_date: str | None = Field( None, description="Upper bound of the date range filter, if any." ) total_notices: int = Field( ..., description="Notices returned by this call, after the notice_type filter, sorting, and cap. Not the feed total (see upstream_total)." ) max_notices_cap: int = Field( ..., description="The max_notices cap applied. Upstream may have more matching notices." ) upstream_total: int | None = Field( None, description=( "The Gazette feed's count of matching corporate insolvency notices (f:total), " "across all pages and before the local notice_type filter. Null when the " "feed does not report it (unknown, not zero)." ), ) page: int = Field( 1, description="The 1-based feed page read by this call (up to 100 entries per page)." ) is_partial: bool = Field( True, description=( "True when matches remain after this page (upstream_total exceeds the feed " "entries on this and earlier pages), or when upstream_total is unknown. " "Notices dropped by notice_type or max_notices do not set it. Re-call with " "page+1 to read on." ), ) skipped_unrecognised: int = Field( 0, description=( "Feed entries on this page dropped because their notice code is not a " "known corporate insolvency code. Counted before the notice_type filter " "and max_notices cap. 0 when none." ), ) unrecognised_codes: list[str] = Field( default_factory=list, description=( "The distinct notice codes behind skipped_unrecognised, sorted. Empty when " "none. These are not personal insolvency results: this tool covers " "corporate insolvency only." ), ) notices: list[GazetteNotice] = Field( default_factory=list, description=( "Matching notices from this page, sorted by severity (desc) then date (desc)." ), ) # ============================================================================= # Sanctions / watchlists (consolidated OFSI + OFAC + EU + UN lists) # ============================================================================= class SanctionsHit(BaseModel): """A single sanctions-list entry matching a screened name.""" model_config = BASE_CFG list_source: str = Field( ..., description="Which consolidated list matched: 'OFSI (UK)', 'OFAC (US)', 'EU', or 'UN'.", ) matched_name: str = Field( ..., description="The exact name or alias on the list that matched the query.", ) is_alias: bool = Field( False, description="True if the match was on an alias/AKA rather than the primary listed name.", ) entity_type: str | None = Field( None, description="'person' or 'entity' where the source distinguishes it; otherwise null.", ) regime: str | None = Field( None, description="Sanctions programme/regime the listing falls under (e.g. 'Russia', 'CUBA', 'DRC').", ) reference: str | None = Field( None, description=( "The source's own reference for the listing (FCDO Unique ID, OFAC uid, " "EU reference number, or UN reference number)." ), ) listed_on: str | None = Field( None, description="Date the entity was listed, where the source provides it (ISO YYYY-MM-DD).", ) class SanctionsScreenResult(BaseModel): """Result of screening one name against the consolidated sanctions lists.""" model_config = BASE_CFG query: str = Field(..., description="The name that was screened.") normalized_query: str = Field( ..., description=( "The normalised form used for matching (upper-cased, accent- and " "punctuation-stripped, whitespace-collapsed)." ), ) entity_type_filter: str | None = Field( None, description="entity_type filter applied to the screen ('person'/'entity'), or null.", ) match_count: int = Field( ..., description="Number of list entries that matched the query." ) lists_screened: list[str] = Field( default_factory=list, description=( "Which consolidated lists were screened for this call: each from its latest " "successful load, which may be a previous load if the latest refresh of that " "list failed (see lists_stale). A list absent here was NOT screened — see " "lists_unavailable. A list that fails part-way through a load contributes " "none of that load's entries." ), ) lists_unavailable: list[str] = Field( default_factory=list, description=( "Expected lists that have no usable load — never loaded, loaded to zero " "records, or last loaded more than 7 days ago — and so were NOT screened. " "Non-empty means this screen is incomplete: a name on one of these lists " "would not appear in hits. Absence of evidence here is not evidence of " "absence." ), ) lists_stale: list[str] = Field( default_factory=list, description=( "Screened lists served from a previous load because the latest refresh of " "that list failed (kept for up to 7 days after its last successful load). " "Their entries were screened, but designations made since list_as_at for " "that list would not appear in hits." ), ) list_as_at: dict[str, str] = Field( default_factory=dict, description=( "Each screened list's own last successful load time on this server (ISO " "8601 UTC), keyed by list name." ), ) is_partial: bool = Field( False, description=( "True when any expected list was unavailable or stale, or any screened list " "was loaded 24 hours ago or more (see list_as_at). When true, an empty hits " "list must be treated as UNRESOLVED, not as clearance." ), ) as_at: str | None = Field( None, description=( "The oldest load time among the screened lists (ISO 8601 UTC; see " "list_as_at), or null when no list was screened. Provenance for the " "screen — the lists update on designation." ), ) hits: list[SanctionsHit] = Field( default_factory=list, description=( "Matching list entries. An empty list means no exact/alias match on the " "screened lists — NOT a guarantee of clearance (see the tool description " "on matching limits)." ), )