Content policies
Available to Enterprise Plan customers only.
Content policies are experimental. The API, the request and response fields, the events, and the classification behavior can change without notice. Zep turns on content policies for each Enterprise account on request. To ask for access, contact Zep Support.
A language model decides whether an item breaks a rule. The model can drop an item that obeys the rules, or keep an item that breaks them. The same input can get a different result on a different run. Test your rules on your own data before you use them. Do not use content policies as your only control for regulated data.
Overview
A content policy keeps a class of information out of the Context Graph. You define the categories and the rules. Zep does not change the episode: the text that you send is stored as you sent it. Zep applies the policy only to the facts, entities, and summaries that ingestion derives from the episode.
Zep evaluates each derived item before it adds the item to the graph:
- When the item does not match a rule, Zep adds the item as it is.
- When the item matches an exclude rule, Zep drops the item.
- When the decision is uncertain, Zep drops the item.
Use a content policy when your application must keep a class of information out of agent memory, for example health conditions in a banking assistant, or religion and sexual orientation in an HR assistant.
A content policy separates three surfaces:
- The project policy is a set of categories and rules that you write at project scope. Each write creates a new immutable revision.
- The bound policy is the policy of one graph. Zep copies the current project revision when the graph is created. The bound policy never changes after creation.
- The episode state is the
content_policyobject on each episode of a protected graph. It records the evaluation status and what Zep dropped.
Before you start
- A protected graph is a graph that has at least one bound rule. The rules come from the project policy or from
content_policyin the create body, or from both. Zep copies the policy into the graph at creation. You cannot add, change, or remove the policy of an existing graph. - Existing graphs are not protected. A user or graph that you created before the policy write has no policy. To protect an existing user, create a new user after the policy write and add the data again. A clone of an unprotected graph is also unprotected.
- A rule change applies only to new graphs. Write and test your rules before you create production users.
- Zep sends derived text to a language model. Zep sends each derived item and the rule text to a language model that Zep operates through its model gateway. Extraction sends the episode text to a language model. The policy classifier receives only derived items, not the source episode. BYOC deployments and accounts under strict data residency cannot use content policies.
- Zep does not derive observations on a protected graph in this release.
Test rules before you use them. Zep has no dry-run operation. Create a test graph with content_policy in the create body. The test graph inherits the current project policy and can add rules, but cannot remove inherited rules. If the combined policy has rules, creation requires the content policy entitlement. Add sample episodes and read the episode state and audit events. Then delete the test graph. The classifier uses a language model, so test each rule with several episodes.
Example: keep health information out of a banking assistant
This example follows one message through a protected graph. A bank runs an assistant that remembers customer requests. The bank must not keep health information about a customer in agent memory.
The content policy methods are available in version 4.0.1 or later of Python zep-cloud, TypeScript @getzep/zep-cloud, and Go github.com/getzep/zep-go/v4. The v3 SDKs do not have these methods.
Write the project policy
The bank writes one category and one rule. Zep stores the policy as revision 1.
Create the user
The bank creates the user after the policy write. The user graph copies revision 1. The graph is now a protected graph. A user that the bank created before the policy write has no policy.
Zep evaluates and drops prohibited artifacts
Ingestion derives facts, entities, and entity summaries from the message. Zep evaluates each artifact before it publishes the artifact. For example, ingestion can extract this fact:
Zep drops the fact. The graph does not contain the health information. The source episode stays stored with its original text.
Read the result
Wait for the task to complete. Then read the episode, the audit events, and the stored facts:
The episode records the match:
The episode event records that the episode is flagged. The audit list contains identifiers, not text.
The project setting include_policy_violating_episodes is false by default, so graph.episode.list omits the episode. The matching fact does not appear in graph.search_edges.
The classifier uses a language model, so its decisions can change between runs.
Evaluation adds language model calls to ingestion, so ingestion of an episode on a protected graph takes longer.
What Zep evaluates
Zep evaluates derived entities, entity attributes, entity summaries, facts, thread summaries, and document summaries. Zep does not evaluate the source episode text.
A classifier that Zep operates answers one question per artifact and rule: does the artifact state or imply the prohibited meaning about a named or identifiable person? Zep converts each answer into one of three decisions.
Matched and uncertain items
Zep drops an item when an exclude rule matches or when the decision is uncertain. Zep does not publish a changed version of the item.
Drops
Zep drops an artifact in these conditions:
- An exclude rule matches the artifact.
- The decision is uncertain.
- The artifact is too large to evaluate.
- The artifact depends on another dropped artifact.
When Zep drops an artifact, the drop is complete:
- A dropped fact is removed. The entities at each end stay under evaluation on their own. The rule for isolated entities can then drop an entity that the episode creates.
- A dropped entity is removed together with every fact of the same episode that connects to it.
- A dropped entity attribute is removed, and the other attributes stay.
- A dropped entity summary keeps the earlier summary in single and batch ingestion. If the entity is new, Zep publishes it without a summary.
- Zep drops an entity that the episode creates when two conditions are true. First, no published fact connects to the entity. Second, Zep dropped the summary, an attribute, or a fact of the entity. An entity that existed before the episode stays.
- An invalidation, expiration, or contradiction that depends on a dropped fact is not applied. Existing facts keep their state.
Permitted artifacts of the same episode are published. One episode can publish permitted facts and drop prohibited ones.
Zep evaluates items of at most 4000 characters. Zep does not cut a longer item, because the part that Zep removes would not be evaluated. Facts and entities are almost never this long.
- A fact, an entity, or an attribute over 4000 characters is not added. The oversize item alone does not flag the episode. Another matching item can still flag the episode. The audit event has
drop_reason: oversize. - A summary is often longer, so Zep evaluates it in parts of at most 4000 characters. When one part matches, Zep drops the new entity summary and keeps the earlier summary. Zep drops a matching thread or document summary.
Source episodes stay stored as written, under the existing retention and deletion behavior and BYOK controls. A content policy is not a promise that prohibited text never reaches Zep. It prevents the derived graph content. An application that must filter source text does so before it sends data to Zep.
The policy model
A policy set has categories and rules.
- A category has a
keyand an optionaldescription. The key is a customer-defined code with 2 to 64 characters. It starts with a lowercase letter and contains only lowercase letters, digits, or underscores. It is unique in the policy set. You filter episodes and audit events by key. The description has at most 500 characters. Zep does not send the description to the classifier. - A rule belongs to one category through
category_key. Itsconditionstates the meaning and subject scope that the rule checks. For an exclude rule, the condition states the prohibited meaning. For an include rule, it states the meaning that an item must have to publish. The deprecateddescriptionfield is an alias forcondition. The condition and description can each have at most 1000 characters.- An exclude rule with a condition must have one to eight
prohibited_examples. It can have zero to eightpermitted_examples. - An exclude rule without a condition must set at least one of
entity_types,edge_types, orpatterns. It cannot setprohibited_examplesorpermitted_examples. - An include rule must set exactly one of
entity_typesoredge_types. It must have a non-emptycondition, at least onepatternsvalue, or both. It cannot set examples.
- An exclude rule with a condition must have one to eight
Each example can have at most 500 characters. For an exclude rule, Zep checks type-only and pattern matches before it sends the condition and examples to the classifier. Zep sends the condition and examples only if neither check has matched the candidate under that rule.
A policy set has at most 16 categories and at most 32 rules. A category without a rule is valid. A rule whose category_key names no category in the same body is rejected. An empty policy set has zero categories and zero rules and means “no content policy”.
Zep returns 400 invalid_request when a key repeats or does not match its pattern. The API returns the same error when a category_key names no category, or a list or string exceeds its limit. The API also rejects a rule that does not meet these requirements. The param field names the failing path, for example rules[2].prohibited_examples.
Write rules as you would brief a careful reviewer. Name the subject scope, such as “a named or identifiable person”. Write prohibited examples that read as extracted facts, and permitted examples that are close to the rule but do not state the prohibited meaning.
Typed rules (experimental)
The condition field is experimental and available to all accounts. The action: include value and the entity_types, edge_types, and patterns fields are in private preview and are available only to enabled accounts. Zep uses exclude when a rule omits action.
The API accepts description as a deprecated alias for condition for one release. A write can send either field. If a write sends both fields, their values must match. The response returns both fields with the same value during this period.
Type scopes
Each entity_types or edge_types list can contain up to 10 ontology types. Project policy writes use the project ontology. Graph and user create requests use the graph ontology, with the project ontology as a fallback. A type outside the write scope returns 400 invalid_request.
An extracted item has a type chain that contains its type and its parent types. A typed rule applies when its type appears in the chain.
An exclude rule without either type list is global. It applies to every candidate kind, including summaries and observations. An exclude rule with entity_types applies to entities, their attributes and summaries, and edges with an endpoint in scope. An exclude rule with edge_types applies to edges. An include rule applies only to entities or edges of its own type. Include rules do not apply to summaries or observations.
Include rules
An include rule must have exactly one non-empty type list and a condition or at least one pattern. Zep first checks the patterns in code. If a pattern matches, the item matches the rule, and Zep does not ask a question. If no pattern matches and the rule has a condition, Zep asks a yes/no question about the condition. The question includes the extracted item and its source episode. If no pattern matches and the rule has no condition, the item does not match the rule. In batch ingestion, Zep asks once for each source episode that contributed the item. One yes result is enough to match the rule. When several include rules apply to an item, one matching rule is enough. An exclude match takes precedence over every include match. If an include question fails, Zep does not write graph data from the episode, but the episode itself stays stored. Zep retries the processing, and the processing fails if the retries do not succeed.
An include rule does not change the summaries of other entities. For example, if Zep drops a customer named Jordan Park, the summary of the Acme Corporation entity can still say that Jordan Park is a customer. To remove this text, add an exclude rule with a condition or patterns that matches it.
Patterns
Zep accepts up to eight RE2 patterns per rule. Each pattern can contain at most 256 characters. Zep matches patterns case-insensitively and without anchors. Before matching, Zep applies Unicode NFKC normalization, collapses whitespace, and trims the text. A pattern cannot match the empty string. Zep evaluates patterns in code and does not send them to a model. When a rule has a condition and patterns, either a condition match or a pattern match matches the rule.
Validation errors
Zep returns 400 invalid_request when:
actionis notexcludeorinclude;- an exclude rule has no type, condition, or pattern;
- an include rule has no type list, both type lists, or no condition or pattern;
- an exclude condition has no
prohibited_examples, or an example field appears on an include rule or an exclude rule without a condition; - a pattern is invalid RE2, matches the empty string, is longer than 256 characters, or the rule has more than eight patterns;
- a rule names a type that is not in the ontology for the write scope;
conditionanddescriptionare both present with different values.
The param field names the invalid field. An invalid action uses rules[i].action. An invalid pattern uses rules[i].patterns[j]. A type error uses rules[i].entity_types[j] or rules[i].edge_types[j]. A condition alias conflict uses rules[i].condition.
When the account flag is off, action: include, entity_types, edge_types, and patterns also return 400 invalid_request. The param field names the unavailable field. The condition field and its description alias remain available.
For example, .* matches the empty string. Zep rejects the rule and names the pattern in param:
This example assumes that the ontology defines Person and WorksFor, and that the account can use typed rules. It sets a typed exclude rule, an include rule, and a pattern rule.
The project policy
The project policy is the default for every graph that you create later. The ContentPolicy response carries the server-owned fields uuid, revision, categories[].id, rules[].id, and created_at. A write body omits them. A write that echoes them is accepted, and Zep ignores the echoed values.
Set the project policy
PUT /project/content-policy replaces the full policy set and returns the new revision with 200. There is no partial update. A body that equals the current revision still creates a new revision.
A PUT /project/content-policy with no body, with {}, or with empty lists clears the project policy. Graphs that you create after the clear are unprotected unless the create body adds rules. Existing protected graphs keep their policy.
The response is the new ContentPolicy:
categories[].id and rules[].id are stable across revisions. Zep matches a category across revisions by key. Zep matches a rule by (category_key, action, sorted entity_types, sorted edge_types, condition, sorted patterns). A category or rule that does not change keeps its identifier.
To clear the policy, refer to the warning at the start of this section.
Read the project policy and its revisions
GET /project/content-policy returns the current revision. A project without a write returns revision 0, the empty policy set.
GET /project/content-policy/revisions lists revisions in descending revision order with page_size and cursor. The list carries total_size. Zep stores every revision that a graph binds until the last graph that binds it is deleted. A revision that no graph binds and that is not current can be removed by retention, so a client accepts a gap in the list.
GET /project/content-policy/revisions/{revision_uuid} returns one revision, or 404 not_found.
Bind a policy at graph creation
A graph copies the current project revision when you create it. graph.create and user.create accept an optional content_policy object with three fields:
project_revisionis optional. When present, the create fails with409 conflictand the codecontent_policy_revision_staleif the current project revision is different. Send it when the policy that an operator reviewed must be the policy that the graph binds.categoriesandrulesadd to the project revision. Akeythat repeats a project category adds rules to that category. A rule that duplicates a project rule by(category_key, description)is ignored.- The combined set must stay inside the limits of the policy model. A combined set over a limit is
400 invalid_requestwithparamset tocontent_policy.rules.
The create body cannot remove a project rule. Additions are additive only.
Store the uuid of the new graph in your database, and pass the UUID on every later call.
The create and the binding are one atomic operation. The 201 response carries the graph, and the bound policy is readable from that moment. A create that cannot persist the binding writes no graph and returns 503 service_unavailable.
A graph is never created unprotected when a policy exists. A create on an account without the content policy entitlement, when the project revision or the create body has at least one rule, returns 403 content_policy_not_entitled and writes no graph.
The bound policy is read-only
There is no update and no delete for the bound policy of a graph. A later write to the project policy does not change a graph that already exists. When a graph needs a different policy, create a new graph.
GET /graphs/{graph_uuid}/content-policy returns the bound set as a ContentPolicy with two more fields:
project_revision is in the graph response so that it has the same name as the project_revision field of the create body. revision is in every ContentPolicy response. The two fields always have the same value on a graph.
The bound set has its own uuid when the graph adds a category or a rule, and uuid equals the uuid of that project revision when the graph adds nothing. Project categories and rules keep the project identifiers. Graph additions get their own identifiers.
Cloning a graph binds the source graph’s policy to the clone. The clone operation does not accept content_policy. The clone copies each source episode with its content_policy object unchanged. It does not copy pending or failed episodes.
Episode state
Every episode of a protected graph carries a content_policy object. An episode of a graph without a bound rule has no content_policy object.
processed keeps its existing meaning. An episode is processed only after content_policy.status reaches complete. A pending or failed evaluation leaves processed: false.
violated, category_keys, and dropped_count can grow after complete. Zep sometimes extracts one artifact from several episodes at once. When that artifact matches a rule, Zep attributes the match to every episode in the group, including an episode that is already complete. status and processed do not change in that case.
Ingestion evaluates every artifact of an episode before it publishes any of them. Retrieval never observes a protected graph state where an artifact is published before its evaluation completed.
Pending and failed episodes
An episode stays pending while ingestion evaluates it. When the classifier fails, Zep retries under the existing ingestion retry policy, and the episode stays pending. When the retry policy is exhausted, status becomes failed and processed stays false. A match that was persisted before the failure stays in violated and category_keys.
No artifact of a failed episode is published. A failure is never recorded as “no match”. A pending or failed episode is excluded from every summary and observation, and from context assembly.
Task results
The graph.add, thread.add_messages, and batch.process tasks report the policy outcome in result. A graph.episode.add call creates a task of type graph.add. A policy violation is an expected outcome, and the task reaches succeeded.
graph.addcarries oneepisode_uuidand onecontent_policyobject.thread.add_messagescarriesepisodes, an array of{episode_uuid, content_policy}with one entry per message.batch.processcarries the aggregateviolated_countandfailed_countinresult.content_policy. Each batch item carries the episodecontent_policyobject once the item completes.
The task stays processing while the episode is pending, including while Zep retries a classifier failure. A classifier failure that exhausts the retry policy is a processing failure. The task reaches failed with error.code set to content_policy_evaluation_failed. The error message names no source text, no artifact text, and no rule text. A thread.add_messages or batch.process task where some episodes completed and some failed is partial, and result carries the completed episodes.
The ingestion status recipe covers task and episode polling.
Flagged episodes in retrieval
A flagged episode is an episode where at least one artifact matched a rule. The project setting include_policy_violating_episodes on GET /project and PATCH /project controls whether three operations return flagged episodes. The default is false.
In both settings:
- The three operations return
pendingandfailedepisodes withprocessed: false. Such an episode has no published artifact, so the list exposes only the source episode. graph.episode.getreturns a flagged episode. A direct read is an explicit request for one known identifier.graph.search_episodesmatches on source text.
The setting never changes the result of graph.get_context, thread.get_context, agent.get_context, summaries, or observations. Context assembly excludes flagged, pending, and failed episodes from source text and from evidence expansion. A permitted fact from a mixed episode stays searchable, and default responses do not expand it to the source episode text. A flagged episode is never an input to a thread summary, a document summary, a user summary, an entity summary, or an observation. When an episode is flagged after a summary that used it was published, Zep marks that summary unavailable and rebuilds it from eligible inputs.
Zep does not derive observations on a protected graph in this release. The observation writer does not evaluate its output against the bound policy, so it does not run.
Filter by violation
graph.episode.list and graph.search_episodes accept content_policy_violated as an exact-match filter in filters. The filter is supported only while include_policy_violating_episodes is true. While the setting is false, the filter is rejected with 400 unsupported_filter.
Cursors
The value of include_policy_violating_episodes is part of the pagination cursor of the three operations. A cursor that was issued under one value and used under the other value returns 400 invalid_cursor. Restart the page walk after you change the setting.
Audit events
POST /graphs/{graph_uuid}/content-policy/events/list lists one event per dropped artifact and one per flagged episode. Events carry identifiers only. An event never contains source text, artifact text, probabilities, questions, person names, or entity names.
An event records that Zep dropped an item. To see the published result, read the graph, for example with graph.search_edges.
An episode-level event has artifact_kind: "episode", drop_reason: "match", and every matched key.
The list orders by decided_at descending and paginates with page_size and cursor. It carries total_size. filters accepts episode_uuid and drop_reason as exact-match filters. Any other filter returns 400 unsupported_filter. The operation is available on an unprotected graph and returns an empty list. Events follow the retention of the audit store, so a client accepts that old events are absent.
Permissions
Policy reads map to the ABAC action project.get at project scope and graph.get at graph scope. PUT /project/content-policy and the include_policy_violating_episodes field of PATCH /project map to project.update. content_policy in a create body needs graph.create or user.add, the same as the create itself. An ingestion-only API key cannot write a policy or change the retrieval setting, and receives 403 permission_denied. Policy-based access control describes how actions attach to API keys.
Entitlement and availability
Content policies need two conditions:
- The account is on the Enterprise plan.
- Zep turned on content policies for the account.
Content policies are available only on Zep Cloud, not on BYOC deployments or accounts under a strict data residency policy.
When one condition is false, the account has no content policy entitlement:
- A
PUT /project/content-policywith at least one rule returns403 content_policy_not_entitled. - A create whose bound policy has at least one rule returns
403 content_policy_not_entitledand writes no graph. The bound policy is the current project revision plus thecontent_policyin the body. A body that adds categories only does not need the entitlement if the project policy has no rules. - A
PUTof the empty policy set is accepted. A project can always clear its policy and create graphs again.
An account that loses the entitlement keeps its protected graphs and the bound policy of each graph. A plan change from Enterprise to a different plan removes the entitlement. While the account has no entitlement, Zep ingests new episodes of those graphs without policy evaluation. When the entitlement returns, protection applies again to new episodes. A new graph on that account is rejected until the project policy is cleared or the entitlement returns.
Zep selects the classifier model, and you cannot change it. The Security & Compliance overview describes the deployment models. To ask for the entitlement, contact Zep Support.
Error codes
Related
- Create Graph and Users and User Graphs describe the create operations that accept
content_policy. - Episodes describes how episodes are stored and retrieved.
- Cloning Graphs describes how a clone binds the source policy.
- Policy-based access control describes the ABAC actions that policy operations map to.