Prompt
Need search that only returns allowed documents
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
If you want a search that only returns allowed documents, the key is to enforce authorization filtering at query time—not just in the UI.
Pattern
- Identify the user / roles / groups
- Attach document permissions
- e.g.
allowed_users,allowed_groups,visibility,tenant_id
- e.g.
- Filter the search query
- Only return docs where the user has access
Example
If your search backend supports filtering, your query should be something like:
SELECT *
FROM documents
WHERE status = 'published'
AND (
visibility = 'public'
OR owner_id = :user_id
OR group_id IN (:user_groups)
)
AND matches_search_terms(...)
If using Elasticsearch / OpenSearch
Use a filter clause so unauthorized docs are never returned:
{
"query": {
"bool": {
"must": [
{ "multi_match": { "query": "search text", "fields": ["title", "body"] } }
],
"filter": [
{ "term": { "tenant_id": "tenant123" } },
{
"bool": {
"should": [
{ "term": { "visibility": "public" } },
{ "term": { "owner_id": "user42" } },
{ "terms": { "group_id": ["grp1", "grp2"] } }
],
"minimum_should_match": 1
}
}
]
}
}
}
Important
- Do not rely on post-filtering after search results are returned
- Enforce permissions in the search layer or a service layer that every search request must pass through
- If documents have per-document ACLs, index those ACL fields and filter on them
If you tell me which search system you’re using (SQL, Elasticsearch/OpenSearch, MongoDB Atlas Search, Azure AI Search, etc.), I can give you the exact query pattern.