Skip to main content

LlamaIndex readers for loading CFPB data as Document objects

Project description

CFPB Connectors

A lightweight Python package for fetching Consumer Financial Protection Bureau (CFPB) data and converting it into LlamaIndex Document objects.

Overview

cfpb-connectors provides reusable CFPB data connectors for retrieval-augmented generation (RAG), semantic search, data analysis pipelines, and LLM-powered applications.

Currently supported:

  • CFPB consumer complaints

Planned future connectors:

  • Mortgages
  • Credit cards
  • Loans
  • Additional CFPB datasets

Installation

Development install

Use this while actively developing the package:

pip install -e .

The -e means editable install. Code changes update immediately without reinstalling.

Future published install

Once published to PyPI, users will install with:

pip install cfpb-connectors

Usage

from cfpb.complaints import CFPBComplaintReader

reader = CFPBComplaintReader(
    companies=["BANK OF AMERICA, NATIONAL ASSOCIATION"],
    start_date_YYYY_MM_DD="2025-01-01",
    end_date_YYYY_MM_DD="2025-01-31",
)

documents = reader.load_data()

print(len(documents))
print(documents[0].text)
print(documents[0].metadata)

Basic RAG Pipeline Example

pip install llama-index-llms-openai llama-index-embeddings-openai
python3 examples/fpb_complaint_reader_basic_usage.py

Date Format

Dates must use ISO format:

YYYY-MM-DD

Example:

start_date_YYYY_MM_DD="2025-01-01"
end_date_YYYY_MM_DD="2025-01-31"

Document Structure

Each CFPB complaint is converted into a LlamaIndex Document.

Text

The document text contains the complaint narrative, prefixed with basic context:

Company: BANK OF AMERICA, NATIONAL ASSOCIATION
Product: Checking or savings account
Issue: Managing an account

<complaint narrative>

Metadata

Each document includes structured metadata:

{
    "complaint_id": "11578145",
    "company": "BANK OF AMERICA, NATIONAL ASSOCIATION",
    "product": "Checking or savings account",
    "sub_product": "Checking account",
    "issue": "Managing an account",
    "sub_issue": "...",
    "date_received": "2025-01-16",
    "date_sent_to_company": "2025-01-16",
    "state": "VA",
    "zip_code": "24012",
    "submitted_via": "Web",
    "company_response": "Closed with explanation",
    "company_public_response": "...",
    "consumer_consent_provided": "Consent provided",
    "consumer_disputed": "N/A",
    "timely": "Yes",
    "tags": None
}

Error Handling

The connector raises clear exceptions when:

  • Required parameters are missing
  • Dates are invalid or incorrectly formatted
  • The start date is after the end date
  • The CFPB API request fails
  • The CFPB API returns an unexpected response

Example:

ValueError: Invalid date '2025-13-01'. Expected format YYYY-MM-DD

Development

Recommended project structure:

cfpb-reader/
├── README.md
├── pyproject.toml
├── src/
│   └── cfpb/
│       ├── __init__.py
│       └── complaints/
│           ├── __init__.py
│           ├── reader.py
│           └── utils.py
└── tests/

Notes

  • Only complaints with consumer-provided narratives are returned.
  • This package currently depends on llama-index-core and requests.

Roadmap

Potential future improvements:

  • Additional CFPB endpoint connectors
  • Additional complaint filters, such as product, issue, state, and ZIP code
  • PyPI publishing

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cfpb_connectors-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cfpb_connectors-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file cfpb_connectors-0.1.0.tar.gz.

File metadata

  • Download URL: cfpb_connectors-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cfpb_connectors-0.1.0.tar.gz
Algorithm Hash digest
SHA256 69a518b7ceff28362a62a96ca0b28e7faab846883470208cc3d1bf25831ad7fe
MD5 e2b1bfd2ce127c5b6b3428a86d654fe4
BLAKE2b-256 1496a6e8074a72248a60f81624c8dbf99915ec14eee60a36fa06dd506bff93bf

See more details on using hashes here.

File details

Details for the file cfpb_connectors-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cfpb_connectors-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21b4e4ba555a297bf39b277082c833e6d20478dfa6d6cacc76445d7bd765e19c
MD5 f7328860368c5db22b9c0f20b72141d5
BLAKE2b-256 d60372b05a048cb63296a3f41d384b8cd3cc6ebc50c7a5793a9a8257b31f4644

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page