Skip to course content
Free generative AI app course

Generative AI Application Development with Python

Unit 05.00: Asking for a shape instead of prose

When the consumer of an answer is code rather than a person, ask for a shape.

Routing on a field versus grepping prose

The same information as a sentence and as a dict.

The code routes on both.

import json

prose = "I think this is probably a billing issue, and fairly urgent."
structured = {"category": "billing", "urgency": "high", "confidence": 0.72}

print(f"prose      : {prose}")
print(f"structured : {json.dumps(structured)}")

print("\nrouting on the structured version:")
print(f"  queue = {structured['category']!r}")
print("routing on the prose version:")
print(f"  'billing' in prose -> {'billing' in prose}   <- breaks on 'invoicing'")

# Prose has to be interpreted by whatever comes next, and the interpretation
# step is a second place to be wrong. When the consumer is code, ask for a
# shape.

The prose router works until the model says "invoicing" instead of "billing", or hedges, or puts the word in a sentence saying it is *not* a billing issue. Each of those is a normal thing for generated text to do.

The structured version is a dictionary lookup. The judgement still belongs to the model; the branch becomes something you can test.

The mistake this prevents

The mistake is asking for prose and parsing it with a regex. The regex becomes the thing you maintain, it accumulates special cases, and every one of them is a phrasing someone observed once.

Takeaway

Ask for a shape when the next step is code. It removes the interpretation step, and interpretation is where meaning quietly drifts.