Skip to main content
In this lesson, you’ll learn how to leverage AI (via Composer) to debug a Flask application. We’ll capture runtime errors in the browser or terminal, feed them into Composer alongside the relevant code, and apply the suggested fixes—all while applying your own programmer intuition.

1. Reproducing & Resolving a Jinja2 Template Error

  1. Start your Flask development server and navigate to the login page.
  2. Log in with valid credentials.
The image shows a login page for a "Task Manager" application with fields for username and password. The browser window is open alongside a code editor displaying project files.
  1. After logging in, you may encounter:
The image shows a web browser displaying a Jinja2 "TemplateNotFound" error for "dash.html" with a traceback of the error. On the left, there's a file explorer showing project files in a code editor.

The Faulty Route

In app.py, the dashboard route is defined as:

Feeding the Error and Code to Composer

Ask Composer:
“Help me debug this error.”
Composer identifies:
Issue: You reference dash.html, but your templates directory contains dashboard.html.
Solution: Rename the template or update the call to render_template('dashboard.html', …).
Always verify your templates/ folder matches the filenames you pass to render_template().

Applying the Fix

Reload the page—the dashboard now renders correctly.

2. Debugging a Database Column Typo

Next, attempt to create a new task via the web interface:
The image shows a "Task Manager" web application interface where a user can create a new task by entering details like title, description, assignee, and status. The interface also includes options to filter tasks by status and assignee.
Submitting the form triggers:

The Faulty INSERT Statement

In app.py, the handler is:

Feeding Code and Error to Composer

Composer responds:
Cause: The column name statu3 is mistyped. It should be status.
Fix: Correct the column name in the SQL statement.
Double-check your database schema (e.g., schema.sql) before running migrations or inserts.

Applying the Fix

Save and refresh—the new task is created successfully.

3. Best Practices for AI-Assisted Debugging

  1. Capture Complete Context
    • Include full tracebacks or error messages.
    • Paste only the relevant code where the error occurred.
  2. Provide Schema or Definitions
    • Share your schema.sql or data models so the AI can verify table and column names.
  3. Trust but Verify
    • Apply your own programming knowledge to confirm suggested changes align with your codebase.
  4. Experiment with Multiple Models
    • If Composer’s recommendation isn’t clear, try another model (e.g., GPT-3.5, GPT-4, Gemini) or start a fresh session.
  5. Use Logs as Supplemental Context
    • Include application or server logs (from SSH sessions or production environments) for deeper insights.

Watch Video