Tell the Agent How to Handle Invalid Inputs
Scenario
Compare three task briefs asking an agent to implement canBook(freeSeats).
Try it yourself
Choose each brief to see whether the agent must guess on freeSeats = -1.
| Case | Result |
|---|---|
| "Implement canBook(freeSeats) returning true when seats are free." | Select a choice above to see what happens. |
| "Implement canBook and handle bad inputs gracefully." | Select a choice above to see what happens. |
| "Reject non-integers or freeSeats < 0 with INVALID_FREE_SEATS; return freeSeats > 0 otherwise." | Select a choice above to see what happens. |
Reveal the explanation
- "Implement canBook(freeSeats) returning true when seats are free."
Underspecified! Agent might return false on -1 or coerce "2" silently.
- "Implement canBook and handle bad inputs gracefully."
Still ambiguous: does "gracefully" mean return false, null, or throw an error?
- "Reject non-integers or freeSeats < 0 with INVALID_FREE_SEATS; return freeSeats > 0 otherwise."
Checkable! Both you and the agent agree on every invalid case before coding.
Always include one invalid-input sentence and one concrete invalid test case in your agent brief.
Your turn
Add an explicit invalid-input sentence to: "Write scoreQuiz(answerKey, studentAnswers) returning total matching answers."
Common mistake Writing "handle unequal lists safely" without naming the expected error code.
Check your work
If answerKey.length != studentAnswers.length, raise/return INVALID_LENGTH.
Quick check
This browser could not save your progress. Changes last until you leave the page.