Keep a missing field separate from zero
Watch short identifiers, spaces and punctuation. · 178 words
Show the model both a real zero and an absent value. The source is an online shop order: discount_percent: 0, gift_message: "Thank you", with no delivery_window field. Use this prompt: Extract discount_percent and delivery_window. Preserve an explicit 0 as 0. If a field is absent, return null for it. Return only those two fields. The expected result is {"discount_percent": 0, "delivery_window": null}. Check it against the source: zero appears, so that result cannot be null; delivery_window does not appear, so it cannot be an empty string or 0. Null means the source did not supply a value.
A second case comes from a weather report. The source says precipitation_inches: 0.0 and wind_mph: 7, but it has no visibility_miles field. The prompt says, Extract precipitation_inches and visibility_miles. Keep the recorded number 0.0, but use null when the requested field is absent. The expected result is {"precipitation_inches": 0.0, "visibility_miles": null}. The check is direct: 0.0 is present in the source, while visibility_miles is not. Never replace an unknown value with zero, because zero claims that a measurement was actually recorded.
Check your recall
For a source with discount_percent: 0 and no delivery_window field, what two values should be extracted?
Check your answer
Return discount_percent as 0 and delivery_window as null. The first value is explicitly present, while the second field is missing.
Sources and credits
Original KeyTouch lesson. Background reading · DAIR.AI · Examples of Prompts.