A wrong answer can come from an expired or unauthorized document rather than from the model. Enforce permission and freshness at retrieval time, and keep the source timestamp in the answer context.
Core concepts
Each chunk should carry tenant_id, allowed_roles, document_status, and valid_until. The server builds the authorization filter before keyword or vector retrieval; the model never receives an unauthorized candidate.
def allowed_filter(tenant_id: str, roles: set[str]) -> dict:
return {
'tenant_id': tenant_id,
'document_status': 'published',
'allowed_roles': {'$overlap': sorted(roles)},
}
query = allowed_filter('tenant-a', {'support'})
assert query['document_status'] == 'published'
Steps and use cases
- Define published, withdrawn, deleted, and expired states.
- Obtain tenant and role claims from the session service and construct the filter server-side.
- Put source time and version into the context so the model can prefer the newest valid evidence.
- Scan for expired documents and create a work queue; never expose unreviewed material automatically.
This is useful for multi-tenant help centers, internal policy libraries, and permission-sensitive technical content.
Official references
OpenAI Retrieval and the OWASP Top 10 for LLM applications.
Last checked: 2026-11-16. Frontend filters are search hints only; authorization belongs to the server.
