What you'll build

A loan eligibility screening system that reads a CSV of applicant data, evaluates each applicant against five bank rules, calculates maximum loan amounts and approval tiers, and outputs two CSV files: one with approved applicants and one with rejections + denial reasons.

πŸ“₯
Load applicants.csv
↓
πŸ”
Check 5 eligibility rules
↓
πŸ’°
Calculate max loan & tier
↓
πŸ“€
Export approved.csv & rejected.csv

Why this project matters

Every major fintech platformβ€”from SouthBank India to M-Pesa Kenya to Jumiaβ€”runs some form of eligibility logic before approving loans. This capstone mimics real production code. You'll learn:

  • How to structure a rule engine using functions and conditionals
  • File I/O and CSV processing with error handling
  • Data validation and type safety (age as int, not string)
  • How rule-based systems feed training data to ML classifiers

Interview angle: Loan eligibility logic is asked in senior Python/data roles. Building this from scratch is a strong portfolio project.

Prerequisites

You should have completed these lessons before starting:

  • Variables & data types β€” int, str, bool, None
  • Conditionals β€” if/elif/else logic
  • Lists & dictionaries β€” storing and iterating data
  • Functions β€” writing reusable functions with return values
  • Error handling β€” try/except blocks
  • File I/O & CSV β€” reading and writing CSVs
  • Pandas (optional) β€” faster CSV processing

Bank policy & eligibility rules

5 Eligibility Rules (must ALL pass)
1
Age: Applicant must be β‰₯ 21 years old
2
Income: Monthly income must be β‰₯ β‚Ή25,000
3
Credit Score: Must be β‰₯ 650
4
EMI Ratio: existing_emi / monthly_income ≀ 0.5 (not over-leveraged)
5
Employment Tenure: β‰₯ 12 months at current job

Bonus: For approved applicants, calculate max loan as monthly_income Γ— 24 and assign tier:

  • Gold: credit_score β‰₯ 750
  • Silver: credit_score 700–749
  • Standard: credit_score 650–699

Data specification

The sample CSV contains 45 realistic applicants with these columns:

Column Type Example Notes
applicant_id str APP0042 Unique identifier
name str Arjun Sharma India/Kenya names
age int 28 Cast from CSV string
monthly_income int 45000 β‚Ή or KSh, no currency symbol
credit_score int 720 300–900 range
existing_emi int 12000 Current monthly obligations
employment_months int 24 Tenure at current job
requested_amount int 200000 Loan requested by applicant
πŸ“„
Sample data file to follow along
Save next to your .py file so pd.read_csv('applicants.csv') works.

Step 1: Load & inspect data

Start by reading the CSV and inspecting a few rows. You can use either the csv module or pandas. Here's the pandas approach (simpler for tabular data):

loan_checker.py Pandas approach
OUTPUTLoaded 45 applicants applicant_id name age monthly_income ... 0 APP0001 Joseph Mwangi 22 87097 ... 1 APP0002 Priya Iyer 26 169794 ... ... applicant_id object age int64 monthly_income int64 ...

Pro tip: Always cast numeric columns to int or float when reading CSVs. String "45000" is not the same as integer 45000 in comparisons.

Step 2: Build the rule engine

Create a function that checks all 5 rules and returns a tuple: (is_eligible, list_of_reasons). This makes testing and debugging easier.

loan_checker.py Rule engine function

Key insight: A function that returns both status AND reasons is production-grade code. It's testable, loggable, and auditable.

Step 3: Apply rules to every applicant

Loop through all 45 applicants, evaluate each one, and collect results into separate approved/rejected lists.

loan_checker.py Batch evaluation

Now you have two clean lists. Let's enrich the approved list with loan tiers and max amounts before export.

Step 4: Calculate loan tier & maximum amount

For each approved applicant, assign a tier based on credit score and calculate the max they can borrow (24Γ— monthly income).

loan_checker.py Tier assignment

Real-world note: In production, you'd also check if the requested amount is reasonable and might offer a lower tier-based cap.

Step 5: Export results to CSV

Write the approved and rejected lists to separate files for the business team to action.

loan_checker.py Export to CSV files
OUTPUTβœ“ Wrote 18 approved to approved.csv βœ“ Wrote 27 rejected to rejected.csv Approved (first 3): applicant_id name age monthly_income tier max_loan_amount 0 APP0002 Priya Iyer 26 169794 Gold 4,075,056

Common pitfalls

String vs. integer on CSV reads
CSV files treat all columns as strings by default. When you do if row['age'] > 21, Python compares strings ("28" > "21" is False alphabetically). Always cast: int(row['age']) or use pd.read_csv(..., dtype={'age': int}).
Missing or NULL values
If existing_emi is missing, the EMI ratio calculation crashes. Always check: if pd.isna(applicant['existing_emi']): applicant['existing_emi'] = 0 before using it.
Off-by-one in age check
Rule says "β‰₯ 21", not "> 21". A 21-year-old should pass. Check: if age < 21 to reject, not if age <= 21.
Double-counting reasons
If you append the same reason multiple times (e.g., re-evaluating EMI), you'll confuse the business team. Return ONE canonical reason per denial, not a list of all failed checks.

Stretch goals (try these)

CLI arguments for input file
Use sys.argv or argparse to accept the CSV filename as a command-line argument instead of hard-coding it.
Config file for thresholds
Move the 5 rules (age, income, score thresholds) to a JSON config file so the bank can change them without editing code.
FastAPI wrapper
Wrap the eligibility checker in a Flask/FastAPI endpoint so loan agents can check one applicant at a time via HTTP.
Scheduled batch processing
Use schedule or cron to run the eligibility checker every night on new applicant CSVs and email results to the team.
ML score blending
Add a machine-learning model score (0–1) alongside the rule-based result and weight them: final_score = 0.7 * rules + 0.3 * ml_model.

Interview Q&A for this project

It prevents over-leveraging. If someone already pays β‚Ή15,000/month on existing loans and earns β‚Ή30,000/month, their EMI ratio is 0.5, which is the max allowed. The bank won't take the risk of adding another loan payment on top. It's a proxy for debt sustainability.
Returning a boolean is easy to test ("is eligible?") but doesn't tell the applicant or agent WHY they were rejected. Returning reasons makes the system transparent and debuggable. In a real system, you'd log/audit every denial reason for compliance.
Check for NULL/NaN at the start: if pd.isna(applicant['credit_score']): reasons.append("Credit score missing"). Or, treat missing as a hard fail (safest for lending). In production, you might pull it from a credit bureau API instead of rejecting outright.
max_loan_amount (24Γ— monthly income) is what SouthBank is willing to lend. requested_amount is what the applicant asked for. If they request more than the max, they either get offered the max or are asked to lower their request. This is a business decision, not a hard reject.
The rule-based approvals/rejections become your training labels. Each approved/rejected applicant is a training example with features (age, income, score, emi_ratio, employment_months) and a label (1 = approved, 0 = rejected). You'd train a logistic regression or tree-based model on 1000s of these rule-labeled examples, then gradually shift from rules to the model for new applicants. This is called "bootstrapping labels" in ML.

Quick quiz

Question 1 of 5
What does the EMI ratio check prevent?
Question 2 of 5
If a CSV says "age" = "28", what's the problem with if age > 21?
Question 3 of 5
Why return (is_eligible, reasons) instead of just is_eligible?
Question 4 of 5
What is max_loan_amount in this project?
Question 5 of 5
How would rule-based rejections become training data for an ML classifier?
0
/ 5
Great work!

How this connects to AI & ML

Every modern credit-scoring system starts as a rule-based engine like yours, then evolves into machine learning. Here's the pipeline:

  • Rules (now): Domain experts (loan officers) code up policy. Fast, auditable, low latency.
  • Bootstrapping (month 1–3): Rules generate labels. Your dataset: 1000s of rule-labeled applicants.
  • ML (month 4+): Train a model on rule-labeled data. The model learns hidden patterns (e.g., "age + income combo is better than income alone").
  • Blending (month 6+): Run both rules and model. Weight them: 70% model, 30% rules (safety net).
  • Full ML (month 12+): Retire rules, run pure ML. Continuously retrain on new applicant outcomes.

You're building the foundation every fintech company relies on.

Logistic Regression Decision Trees Feature Engineering Label Generation Model Monitoring

Mini challenge

Add a 6th rule: "Requested loan amount must not exceed 50Γ— the applicant's monthly_income." Implement it in the check_eligibility function without breaking the existing 5 rules. Test on one applicant manually and print the result.

Add another if check before the return statement. The check is: if applicant['requested_amount'] > applicant['monthly_income'] * 50: reasons.append("..."). Update the eligibility logic to require len(reasons) == 0.

Key takeaways

  • Rule-based systems are production-grade when they return both a decision and reasons (transparent, auditable).
  • Always cast CSV columns to the right type (int/float); string comparisons behave differently ("28" vs 28).
  • Function signatures that return actionable data (not just True/False) are easier to test and integrate.
  • Loan eligibility logic feeds training data to ML classifiers; you're building the first step of an AI pipeline.
  • Export clean, well-named CSV files; downstream teams (agents, ops, risk) depend on your output column names.