Menu
CoddyTech

Lead Extractor

Part of the Calling Models From Code section of Coddy's AI Engineering journey. Lesson 22 of 22.

challenge icon

Challenge

Hard

Sales 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.

  1. Define a JSON schema for an object with four required fields: name, email and company_name (strings) and seats (an integer), with "additionalProperties": False.
  2. Print the header name,email,company,seats.
  3. For each message, send it as the only user message with that schema in output_config, model="claude-opus-5-5" and max_tokens=300, and parse the text block with json.loads.
  4. If the email has no @, the message gave no email: print Skipped 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.
  5. 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: 25

The 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