Query policies are managed through the API. You need an API key for the company that owns the access rule.
Prerequisites
- An access rule your company owns, and its ID
- An API key for your company
- Familiarity with access rules
Select the columns in the access rule
A policy can only name columns the access rule’s NQL selects. A Rosetta Stone attribute counts only when the NQL selects it from_rosetta_stone. Selecting a dataset column that is mapped to the attribute is not enough.
The examples in this guide use an access rule named customer_segments_ar, shared by a company with the slug acme:
Once an access rule has a policy, partners can read a Rosetta Stone attribute through it only if the NQL selects that attribute from
_rosetta_stone. Select every attribute partners need this way before you attach the policy.Write the policy
Start from what partners should be able to do, and open only that. Any usage the policy doesn’t set for a column falls back todefault, and any usage default doesn’t set is denied.
Pick the pattern closest to your use case:
- Join only
- Hashed values only
- Counts only
Partners can join on email addresses to enrich their own records, but never return one. The join-required rule means the access rule is usable only when joined to the partner’s own data on email.A partner query that satisfies this policy:
segment_id needs projection set to allow as well as group_by.
For every option, including nested columns and external functions such as AI_COMPLETE, see the Query Policies reference.
Attach the policy
Send the policy as the body ofPUT /v2/access-rules/{access_rule_id}/query-policy. This replaces any policy the access rule already has.
200 response returns the stored policy. The policy applies to every query compiled after that.
To create an access rule with a policy already attached, add the same object as query_policy in the body of POST /v2/access-rules.
Fix validation errors
Narrative checks the policy against the access rule’s NQL before storing it. An invalid policy returns400, leaves the current policy in place, and lists every problem in error_description:
The Query Policies reference lists every message.
Check the policy
Read the stored policy back:404 means the access rule has no policy. Partners the access rule is shared with can call the same endpoint, and the policy also appears as query_policy in every v2 access rule response.
Change or remove the policy
To change the policy, send the complete new policy withPUT. There is no partial update: rules you leave out of the new policy are gone.
To remove the policy, send DELETE:
204 response means the access rule has no policy, whether or not it had one before. Partners can then use every column the access rule selects without restriction.
When a partner’s query returns fewer rows
A query that breaks a policy doesn’t fail. Narrative leaves that access rule out of the query, so it contributes no rows, and the query returns rows from any other access rules it reads. A partner who expects rows from your access rule and gets none should compare their query against the policy:- Does the query return a column’s raw value where the policy only allows functions of it?
- Does every function on a restricted column appear in the matching list?
- If the policy has a join-required rule, does the query inner join the access rule directly to one of the partner’s own datasets on the required keys?
Related content
Access Rules
Why query policies exist and how Narrative enforces them
Query Policies Reference
Every field, mode, and validation error
Joining Datasets
Write the joins a join-required rule expects
Set a Query Policy API
Request and response schemas

