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) complaint data and converting it into LlamaIndex Document objects.

Overview

cfpb-connectors provides reusable CFPB data connectors for RAG, semantic search, data analysis pipelines, and LLM-powered applications.

Currently supported:

  • CFPB consumer complaints

Installation

Development install

pip install -e .

Future published install

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",
    verbose=True,
)

documents = reader.load_data()

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

Optional Parameters and Defaults

All parameters are optional.

Default behavior:

  • If companies is missing → fetch all companies
  • If start_date_YYYY_MM_DD is missing → defaults to Jan 1 of current year
  • If end_date_YYYY_MM_DD is missing → defaults to today
  • If verbose=True → logs execution details

Examples:

# All companies, current year
CFPBComplaintReader(verbose=True)

# One company, default dates
CFPBComplaintReader(
    companies=["BANK OF AMERICA, NATIONAL ASSOCIATION"],
    verbose=True
)

# All companies, custom date range
CFPBComplaintReader(
    start_date_YYYY_MM_DD="2025-01-01",
    end_date_YYYY_MM_DD="2025-01-31",
    verbose=True
)

# One company, missing end date
CFPBComplaintReader(
    companies=["BANK OF AMERICA, NATIONAL ASSOCIATION"],
    start_date_YYYY_MM_DD="2025-01-01",
    verbose=True
)

Basic RAG Pipeline Example

Install dependencies:

pip install llama-index-llms-openai llama-index-embeddings-openai

Run example:

python3 -m examples.cfpb_complaint_all_parameters

Batching (Recommended for Large Data)

import time
import logging
from llama_index.core import VectorStoreIndex

BATCH_SIZE = 100
SLEEP_SECONDS = 1

index = None
total_batches = (len(documents) + BATCH_SIZE - 1) // BATCH_SIZE

for i in range(0, len(documents), BATCH_SIZE):
    batch = documents[i:i + BATCH_SIZE]
    batch_num = (i // BATCH_SIZE) + 1

    logging.info(f"Embedding batch {batch_num}/{total_batches}: {len(batch)} docs")

    if index is None:
        index = VectorStoreIndex.from_documents(batch, embed_model=embed_model)
    else:
        for doc in batch:
            index.insert(doc)

    time.sleep(SLEEP_SECONDS)

Date Format

YYYY-MM-DD

Document Structure

Text

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

<complaint narrative>

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 errors when:

  • Dates are invalid
  • Start date > end date
  • API request fails
  • API response is malformed

Example:

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

Notes

  • Only complaints with narratives are returned
  • No embedding or batching is handled in this package
  • Those belong in the application layer

Roadmap

  • More CFPB datasets
  • Additional filters (product, issue, state, ZIP)
  • PyPI publishing
  • LlamaHub integration

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.2.0.tar.gz (7.6 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.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cfpb_connectors-0.2.0.tar.gz
  • Upload date:
  • Size: 7.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 0c3e4b1ead0019852a35d18a41e4a4448b663c86a6dc1c67ebd857e824e52107
MD5 c355a4cd0de9ba286017253d577d86d7
BLAKE2b-256 d217bd2e3c0fd0864fe690e82a82c1bc0cac61dc13be6b1f69e164951d4fce3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cfpb_connectors-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83080356d732003c8ff923ac9fb3d8b067280b7e749cbdaa6be0fb696cd1e985
MD5 c2d2d409bfbc26bccca96d3c6e7fbcba
BLAKE2b-256 2ccfab06a741fee161d13ffa1967e1a848a9fdcfd6f379a2c558d2d28def2fd2

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