Lead Extractor
Part of the Calling Models From Code section of Coddy's AI Engineering journey. Lesson 22 of 22.
Challenge
HardSales gets messages from people who want team accounts. Turn each message into a row of a CSV file. The input is the number of messages, then one message per line; the starter reads them into lines.
- Define a JSON schema for an object with four required fields:
name,emailandcompany_name(strings) andseats(an integer), with"additionalProperties": False. - Print the header
name,email,company,seats. - For each message, send it as the only user message with that schema in
output_config,model="claude-opus-5-5"andmax_tokens=300, and parse the text block withjson.loads. - If the email has no
@, the message gave no email: printSkipped line <number>: no email(lines are numbered from 1) and move on. Otherwise print the four values joined by commas, in the header's order. - At the end, print
Total seats:and the sum of the seats of the rows you printed.
For example, for this input:
2
Hi, I'm Dana Lee from Northwind (dana@northwind.io). We need 25 seats for our team.
Hello! Marco Rossi at Vela Studio here. We want 8 seats, how much would that cost?the program prints:
name,email,company,seats
Dana Lee,dana@northwind.io,Northwind,25
Skipped line 2: no email
Total seats: 25The schema makes the reply valid JSON with every field present, but a field can still be empty when the message never said it. Your code checks the values before it trusts them.
Try it yourself
import coddy_ai as anthropic # in production: import anthropic
import json
client = anthropic.Anthropic()
count = int(input())
lines = [input() for _ in range(count)]
# Write your code below
All lessons in Calling Models From Code
Practice on your own: Online Python compiler