{"success":true,"name":"fail-fast-reject-bad-input-at-the-door","description":"Writing a function or endpoint that receives data from outside","category":"ai-brimind","path":"ai-brimind/fail-fast-reject-bad-input-at-the-door/SKILL.md","file":"SKILL.md","content":"---\nname: fail-fast-reject-bad-input-at-the-door\ndescription: \"Writing a function or endpoint that receives data from outside\"\n---\n\n# Fail Fast: Reject Bad Input at the Door\n\n## When to use\nYou are writing code that receives input (user data, API payload, function arguments) and you haven't checked it before using it.\n\n## Example request\nUsing a field deep inside a function that arrived empty → the crash happens far from the real cause; validation belonged at the entry. Trusting the frontend already checked the data → the API gets called directly and breaks; the door is where the check lives. Letting a wrong type travel through five functions → the error message points nowhere useful; that is late failure. Checking inputs at the top with clear messages → problems die in one line; that is a guard clause.\n\n## Instructions\nAdopt the mindset of a bouncer who checks IDs at the entrance, not on the dance floor. When writing anything that receives data: (1) At the very top, list what you require: which fields must exist, what types, what ranges, what formats. (2) Check each requirement FIRST, and when a check fails, stop immediately with a message that names exactly what was wrong and what was expected — 'email is missing' beats 'something went wrong'. (3) Never let unchecked data travel deeper into the code, because a failure three layers down points at the wrong suspect. (4) Do not silently 'fix' bad input by guessing what was meant — guessing hides the real problem upstream. If you don't know what valid input looks like, ask or check how callers actually use it before deciding. Only proceed with the main logic once inputs are confirmed valid, and explain how each guard maps to a real requirement, not just paranoia.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #260\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}