WRITE · TRACE · UNDERSTAND
Filter retrieval permissions before selecting context
Implement authorized_topk(docs,tenant,roles,k).
Read lesson: Filter retrieval permissions before selecting context →
Your experiment
Implement authorized_topk(docs,tenant,roles,k). Each doc has id,tenant,roles (empty means tenant-public),score,text. Keep same-tenant docs whose roles intersect caller roles or are empty; rank by descending score then id; return at most k ids. Reject k<0. Do not mutate docs.
Python runs in your browser. Your draft stays on this device.
What to look for
Authorization must precede data disclosure. This local policy tests access filtering; it does not claim that role checks detect prompt injection or that a model will obey instructions once untrusted text enters its context.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.
