Back to Portfolio

Foundations · Python and API Fundamentals

Ticket Triage Lab
Support Classification

Build a support ticket classifier from scratch. Start with rule-based routing, then integrate a real AI model, measure accuracy on labeled examples, and understand where your Python code ends and the API boundary begins. Ten lessons, eight to twelve study sessions.

Project SetupParse Input DataDefine ContractsRule BaselineModel IntegrationEvaluation

Status: Guided Tutorial

A ten-lesson interactive tutorial covering Python setup, JSON parsing, Pydantic validation, rule-based classification, API integration with OpenAI, and evaluation metrics. Includes starter code, tests, and a complete reference implementation. Designed as your first experience building a Python program that calls an external API.

The problem

Support teams face inconsistent ticket routing:

How it works

Read a ticket from JSON. Validate its structure with Pydantic. Route it through one of two classifiers: a rule-based keyword matcher that's fast and free, or an OpenAI API call that's accurate and costs money. Log the prediction with timing and token usage. Then compare both against human labels to see which approach matches reality better.

01JSON file with ticket ID and text
02Python reads and validates ticket
03Choose route: rule-based or API call
04Rule classifier: keyword matching with ranked precedence
05API classifier: OpenAI structured output with schema
06Category + reason returned and logged

What you'll build

Ten lessons, each with clear learning objectives and hands-on code:

Lesson 1

Set up and run a file

Python environments, virtual environments, running your first script.

Lesson 2

Read and inspect a ticket

JSON parsing, dictionaries, understanding structured data.

Lesson 3

Define input/output contracts

Pydantic models, validation, schema-driven development.

Lesson 4

Implement a rule baseline

Keyword matching, loops, conditional logic, ranked evaluation.

Lesson 5

Trace the full program

File I/O, data flow, debugging with print statements.

Lesson 6

Understand the API boundary

Requests/responses, tokens, context windows, structured output.

Lesson 7

Implement the live model call

OpenAI SDK, API authentication, handling latency and cost.

Lesson 8

Measure against labels

Accuracy calculation, confusion matrices, dev vs. holdout evaluation.

Lesson 9

Test failures and recover

Error handling, debugging strategies, understanding root causes.

Lesson 10

Rebuild and prepare for portfolio

Write a README, GitHub publication, interview practice.

Key learnings

This project teaches the engineering fundamentals needed to build any AI application:

Python fundamentals

Variables, functions, loops, conditionals, file I/O, and modules.

Data validation

Pydantic schemas enforce structure at boundaries, not just at parse time.

Rules vs. AI

Compare simple keyword matching against a real model on dev and holdout examples.

API integration

Send structured requests, handle responses, understand token costs and latency.

Evaluation design

Labeled examples, dev/holdout splits, accuracy metrics, error analysis.

Error recovery

Missing files, JSON errors, validation failures, API timeouts, and retries.

Why this project

Most AI tutorials skip the fundamentals. They assume you already know Python, or they gloss over the difference between a local script and an API call. This project starts from zero: installing Python, writing your first file, understanding JSON, building a schema, then gradually introducing complexity until you have a complete classifier you can run live.

By the end, you'll understand the real work: defining what success means (evaluation), building something simple that works (rules), knowing when to add complexity (the model call), and measuring whether it helped (accuracy on labeled data).

Your tech stack

Python 3.12PydanticJSONOpenAI APIPytestSQLiteGitHub

Ready to build?

Clone the starter template, follow the ten lessons step by step, and have a working support classifier running on your machine within a few study sessions.