The Scenario
Your Flask API returns 500 Internal Server Error on POST /api/users but GET /api/users works fine. You have the error log and the route handler code.
Direct Prompt (Superficial)
Prompt: “My Flask API returns 500 on POST /api/users but GET works fine. What’s wrong?”
Output:
Here are some common causes of 500 errors on POST routes:
1. Missing request body parsing
2. Database connection issues
3. Validation errors
4. CORS configuration
5. Missing required fields
Try checking your error logs for more details.
Generic checklist. Doesn’t look at your actual code.
CoT Prompt (Deliberate)
Debug this systematically. For each step,
state what you're checking and why.
My Flask API returns 500 on POST /api/users
but GET /api/users works fine.
Error log:
sqlalchemy.exc.IntegrityError:
(psycopg2.errors.NotNullViolation)
null value in column "created_at"
Route handler:
@app.route('/api/users', methods=['POST'])
def create_user():
data = request.get_json()
user = User(
name=data['name'],
email=data['email']
)
db.session.add(user)
db.session.commit()
return jsonify(user.to_dict()), 201
Walk through the debugging process step
by step.
Model Output (CoT)
Step 1: Read the error message
The error is NotNullViolation on "created_at".
This means the database requires created_at
but it's not being set.
Step 2: Check the route handler
The User() constructor sets name and email
but NOT created_at. The column likely has
nullable=False in the model definition.
Step 3: Why GET works but POST doesn't
GET reads existing rows (which have
created_at). POST creates new rows without
setting it → DB constraint violation.
Step 4: The fix
Option A: Add a default in the model:
created_at = db.Column(db.DateTime,
default=datetime.utcnow)
Option B: Set it in the route:
user = User(name=data['name'],
email=data['email'],
created_at=datetime.utcnow())
Key insight: The CoT prompt didn’t just say “think step by step” — it said “debug systematically, state what you’re checking and why.” This guided the model to follow a real debugging methodology: read the error, trace the code, explain the asymmetry, propose a fix. Domain-specific CoT triggers produce domain-specific reasoning.