๐งชTDD Challengeยทbeginnerยทโฑ๏ธ 20โ35mยทโญ 100 XP
M-016Structured JSON Output
Description
Nebula Corp's API team needs prompts that reliably produce valid, structured JSON output from an LLM. The current prompts return free-form text that breaks downstream parsers. Write a prompt-generating function that instructs the model to return data in a specific JSON schema โ and make sure every test case passes.
Test Cases (5)
Includes JSON instruction
The prompt must mention JSON to instruct the model on the output format
Input:{ "type": "user_profile", "fields": ["name", "age", "email"] }
Expected:CONTAINS:JSON
Lists all requested fields
The prompt must reference every field the caller requested so the model knows the schema
Input:{ "type": "user_profile", "fields": ["name", "age", "email"] }
Expected:CONTAINS_ALL:name,age,email
Prohibits extra text outside JSON
The prompt must include a constraint that prevents the model from adding text outside the JSON
Input:{ "type": "product_review", "fields": ["title", "rating", "summary"] }
Expected:CONTAINS_ANY:only,no explanation,no markdown,no extra,raw JSON
Adapts to different task types
The prompt must dynamically include the task type and its specific fields
Input:{ "type": "weather_report", "fields": ["city", "temperature", "conditions"] }
Expected:CONTAINS_ALL:city,temperature,conditions,weather_report
Works with single-field schema
The prompt must handle minimal schemas with just one field
Input:{ "type": "sentiment", "fields": ["label"] }
Expected:CONTAINS_ALL:label,JSON
Related Lessons
Click Run / Check to validate your solution