Skip to main content
Loading navigation
Back to prompt library

Build a Trade Invoice Entity Reconciliation and Queue Dispatcher — implementation

Linked challenge: Build a Trade Invoice Entity Reconciliation and Queue Dispatcher

Prompt source

implementation66 lines11 sectionsNo variables1 code block
## Build
Cross-reference counterparty entities from commercial trade invoices against legal entity records from the GLEIF API. Queue ambiguous counterparties for human investigator review with automated discrepancy scoring.

## User
Trade finance compliance analyst

## Workflow
1. Ingest simplified normalized trade invoice records containing seller names, buyer identifiers, and stated addresses.
2. Query simulated GLEIF API entity records to match company legal names and mapped BIC identifiers.
3. Compute fuzzy name similarity and address matching scores to isolate unresolved counterparty discrepancies.
4. Generate a prioritized compliance investigation queue with structured resolution decision forms for analysts.

## Interface
Browser-based queue console displaying flagged invoice counterparties, candidate legal entity profiles, match confidence scores, and adjudication action buttons.

## Data
Use a mock fixture of 50 normalized trade invoice JSON records paired with simulated GLEIF Golden Copy entities accessible via a local FastAPI mock.
Starter examples below are synthetic. They are not downloaded records.

## Source
[GLEIF API](https://www.gleif.org/en/lei-data/gleif-api)
Applies GLEIF API search parameters including entity legal names, BIC code mapping, and fuzzy address matching from source excerpt 0.

## Tools
pydantic-ai, fastapi, rapidfuzz.
Pydantic AI enforces type-safe schemas across incoming invoice counterparties and outbound analyst review payloads.
Fast local or hosted LLM via OpenAI-compatible endpoint for synthesizing discrepancy explanations from candidate records.

## Deliverables
Submit runnable source, pinned dependencies, setup commands, a working interface, example outputs, and a recorded end-to-end demo. Include tests and an action log.

## Acceptance
- Correctly maps exact matches to approved status without manual triage.
- Assigns all invoice counterparties with confidence scores below 0.85 to the analyst review queue.
- Outputs structured JSON queue items containing normalized invoice details and top 3 candidate LEI matches.

## Starter Examples
```json
[
  {
    "input": {
      "invoice_id": "INV-2024-001",
      "counterparty_name": "Apex Global Logistics Inc",
      "bic": "APEXUS33",
      "country": "US"
    },
    "expected_output": {
      "action": "AUTO_RESOLVE",
      "matched_lei": "5493006MHB84DD0ZWV18",
      "confidence_score": 0.98,
      "queue_required": false
    }
  },
  {
    "input": {
      "invoice_id": "INV-2024-002",
      "counterparty_name": "Apex Logistix Corp",
      "bic": "UNKNOWN",
      "country": "US"
    },
    "expected_output": {
      "action": "QUEUE_FOR_REVIEW",
      "candidate_leis": [
        "5493006MHB84DD0ZWV18",
        "5493008KJZ12BB9YYA44"
      ],
      "confidence_score": 0.71,
      "queue_required": true
    }
  }
]
```

## Safety
Simulates all corporate registry updates; does not freeze commercial payments or initiate binding legal action.
Use mock external writes. Require human review before any real deployment.