FastAPI: preserve requirements through advanced agent edits
Work through Python examples of real application boundaries: Preserve tenant authorization inside an atomic FastAPI update; Keep a FastAPI order update and its outbox event in one transaction. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.
Download the FastAPI rule pack ZIP · Inspect the YAML rules
Python
A read-then-write authorization check has two boundaries: who can see the row, and whether the write still applies the same scope. Put tenant, owner, and pending status into the UPDATE itself. A concurrent cancellation can then change at most one pending row.
Broken edit flagged · corrected edit passes
Python
Publishing a message after a database write leaves a crash window. An outbox row is written with the order state, so a worker can deliver it later. A unique event_key prevents accidental duplicate event insertion; a delivery consumer still needs its own deduplication.
Broken edit flagged · corrected edit passes
Introductory framework example
Use a correction as a saved requirement
Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.
Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.
Official FastAPI documentation · All language and framework recipes