๐งชTDD Challengeยทbeginnerยทโฑ๏ธ 20โ35mยทโญ 130 XP
M-007Extract Structured Data from Text
Description
Nebula Corp's finance team receives hundreds of invoices as plain text emails. They need a function that builds a prompt to extract structured JSON data (vendor, amount, date, invoice number) from unstructured invoice text. The current implementation produces a vague prompt that returns inconsistent formats. Build a robust prompt constructor that reliably extracts the right fields as valid JSON.
Test Cases (6)
Includes all requested fields
The prompt must reference every field name from the fields array
Input:"Invoice from Acme Corp, $500, dated Jan 15 2025, INV-001", ["vendor", "amount", "date", "invoiceNumber"]
Expected:CONTAINS_ALL:vendor,amount,date,invoiceNumber
Requests JSON output format
The prompt must instruct the model to respond in JSON format
Input:"Payment of $200 from WidgetCo", ["vendor", "amount"]
Expected:CONTAINS_ALL:JSON,vendor,amount
Includes the invoice text
The prompt must include the actual invoice text to extract from
Input:"Invoice #9921 from CloudHost Ltd for $1,250.00 due March 1", ["vendor", "amount"]
Expected:CONTAINS:CloudHost Ltd
Prohibits extra text outside JSON
The prompt must constrain the model to output only JSON, no surrounding text
Input:"Bill from DataPipe Inc", ["vendor"]
Expected:CONTAINS_ANY:only,ONLY,no markdown,no explanation,raw JSON,no code fences
Handles null for missing fields
The prompt should instruct the model to use null for fields not found in the text
Input:"Quick bill: $50", ["vendor", "amount", "date"]
Expected:CONTAINS:null
Adapts to different field sets
The prompt must dynamically include whatever fields are passed in
Input:"Subscription renewal $29.99", ["product", "price", "renewalDate"]
Expected:CONTAINS_ALL:product,price,renewalDate
Related Lessons
Click Run / Check to validate your solution