A lightweight Flask REST API that maps three filters (situation
, level
, file_type
) to one of five system prompts.
Built with a clean MVC split (view + service), centralized validation, and consistent JSON error responses.
- Language: Python 3.9+
- Framework: Flask 2.3+
- Pattern: MVC (views + services), no model layer by design
- Testing: pytest
Clone the project and set up a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python run.py
Server will be available at:
http://127.0.0.1:8000
📡 API Usage
POST /api/match-prompt
Request Body
json
{
"situation": "Commercial Auto",
"level": "Structure",
"file_type": "Summary Report",
"data": ""
}
Success Response (200)
json
{ "prompt": "Prompt 1"
}
Error Responses
HTTP Code Error Code Example
400 Missing Data {"error":{"code":"Missing Data","message":"Missing field(s): file_type"}}
422 Invalid Prompt {"error":{"code":"Invalid Prompt","message":"No prompt found for provided filters."}}
415 Unsupported Media Type {"error":{"code":"Unsupported Media Type","message":"Use application/json"}}
🔧 Example cURL
bash
curl -s -X POST http://127.0.0.1:8000/api/match-prompt \
-H "Content-Type: application/json" \
-d '{"situation":"Commercial Auto","level":"Structure","file_type":"Summary Report","data":""}'
🧪 Running Tests
Tests are written using pytest and cover:
Valid prompt matching
Missing field validation
Invalid prompt combination
Run tests with:
bash
pytest -q
🧠 Design Notes
Architecture: views.py handles HTTP; services.py contains business logic; prompts.py stores rules.
Validation: Centralized in validators.py with type checks and required fields.
Normalization: Case-insensitive matching with synonyms (e.g., "workers comp" → "Workers Compensation").
Error Handling: Custom exceptions in exceptions.py, global handlers in error_handlers.py for consistent JSON.
Extensibility: Add a new rule by editing PROMPT_RULES in prompts.py only.
Testability: Pytest suite (tests/) verifies happy-path and error cases.
🩺 Health Check (Optional)
If enabled in views.py:
bash
curl http://127.0.0.1:8000/api/health
# {"status":"ok"}
License
This project is provided as part of the Optimalex Software Engineering Research Project Internship exercise.