Implementation Guide

    Segmenting 42 CFR Part 2 Substance Use Records Out of a LlamaIndex Vector Index

    Treat index-level separation as the primary control: keep Part 2 content in its own index, namespace or collection, tag it at ingestion, and make retrieval choose a partition based on the caller's role and purpose. Use metadata filters as a second layer, not the only one. Then enforce policy at runtime on each retrieval and generation step, so what was allowed, redacted or blocked is recorded as evidence. As of November 2026, the 2024 final rule does not require segmentation for recipients under a treatment, payment and health care operations (TPO) consent, so the pattern you choose is a risk decision. This is not legal advice.

    What Part 2 changes for a RAG index

    42 CFR Part 2 restricts the use and disclosure of records that identify a patient as having, or having had, a substance use disorder (SUD), whether directly, by reference to publicly available information, or through verification by another person. It applies to records created by a federally assisted SUD program for treatment, diagnosis for that treatment, or referral for that treatment. Disclosure is consent-based, and a written consent must include a statement that records disclosed under it may be redisclosed by the recipient and no longer protected by Part 2. SUD counseling notes need consent for any use or disclosure, apart from listed exceptions.

    The 2024 final rule aligned Part 2 more closely with HIPAA. A patient can give a single consent for all future TPO uses and disclosures, and a HIPAA-covered recipient of a record under that consent can redisclose it as HIPAA allows, except in legal proceedings against the patient. The rule also states that recipients under a TPO consent are not required to segregate records or segment Part 2 data. It acknowledges that tagging, tracking and segmenting become hard when consent is narrowed or revoked.

    For a RAG system, this means segmentation is a design choice justified by risk, not a stated mandate. Any use or disclosure must still be limited to the information necessary for its purpose, and a retrieval that hands Part 2 content to an unauthorized user, agent or downstream model is a disclosure. Whether your records fall under Part 2, and under which consent, needs legal review.

    Segmentation patterns compared

    LlamaIndex lets you separate content by building distinct indexes, by using namespaces or collections in the underlying vector store, or by tagging nodes with metadata and filtering at query time. OWASP guidance on RAG security recommends partitioning by classification, using separate namespaces, collections or indices, and warns that embeddings from one group can be retrieved for another group's queries when everyone shares one store. How filtering and namespaces behave differs across vector store backends, so test each one directly.

    • Separate index or store: Strongest isolation. Part 2 content has its own storage, credentials and query path, so a missing filter cannot expose it. Costs more to operate, and cross-partition queries need explicit routing.
    • Namespace or collection in a shared store: Good isolation with less infrastructure. The partition is chosen at query time, so a wrong or default namespace becomes the failure point. Confirm your backend supports it and that access control applies per namespace.
    • Shared index with metadata filters: Simplest to run, weakest on risk. Part 2 and non-Part 2 nodes share a partition, so any query path that omits or misconfigures the filter is a leak path.

    Choosing a pattern by risk

    Start from who can ask questions and what else is in the index. If general staff, broad assistants or agents with tool access query the same corpus that holds Part 2 content, use a separate index or store. The cost of a missed filter is then a structural impossibility rather than a code review item. If only a small, authenticated clinical group queries the corpus and the Part 2 volume is modest, a namespace or collection with enforced per-namespace access may be sufficient.

    A shared index with metadata filters is defensible mainly where every query path goes through one reviewed retriever factory and the filter is injected server-side, never supplied by the client or the prompt. Even then, treat it as a secondary layer. Filters fail quietly: a new query engine, a test script or a chat feature built by another team can skip them, and nothing errors. Derived artifacts such as response caches and derived indexes hold copies of content, so they need the same partitioning and deletion rules as the source index.

    Implementation sequence

    Build in this order so each step has something to rely on. Keep consent scope and the redisclosure notice with the record from the first step, because retrieval policy will depend on them.

    • 1. Classify at ingestion: Record the source system and whether it originates from a Part 2 program. Tag content that identifies a patient as having or having had an SUD. Treat SUD counseling notes as their own category. Default unknown origin to the restricted path until reviewed.
    • 2. Write metadata onto every node: Attach a classification label, consent scope, redisclosure-notice reference and source identifier as node metadata. Make sure the metadata is carried through chunking so every chunk keeps the label.
    • 3. Route to the right partition: Send Part 2 nodes to their own index, namespace or collection at write time. Do not rely on a later filter to separate them. Keep embeddings, caches and derived indexes inside the same partition.
    • 4. Resolve the partition at query time: Derive the partition and filters on the server from the authenticated role and the stated purpose of the request. Limit what is returned to what that purpose needs. Fail closed if role or purpose is missing.
    • 5. Handle consent changes: Assign an owner for revocation, narrower consent and restriction requests. On a change, re-tag or remove affected nodes, then purge them from caches and derived indexes, and re-run retrieval tests to confirm they no longer appear.
    • 6. Test the failure paths: Run queries with the filter omitted, the namespace defaulted and the role downgraded. Confirm Part 2 content never reaches the prompt, and that results from these cases are blocked or empty.

    Where content leaks outside the index

    Index design covers storage, but retrieval output travels further. Chat memory can retain Part 2 passages from an earlier authorized turn and surface them in a later turn for a different purpose or user. Rerankers and other post-retrieval steps receive node text, so they must sit inside the same authorization boundary as the retriever. Response caches can answer a later, unauthorized query from stored text without touching the index at all. Shared embedding models are less of a concern than shared storage, but any component that stores or logs text should be treated as part of the partition.

    The practical mitigation is to scope session state, caches and logs to the classification of the data they contain, and to delete from all of them when consent changes. Re-indexing deserves particular care: a rebuild from a raw source that still contains revoked content will quietly restore it, so the consent state should be checked as part of the ingestion pipeline itself.

    Application-level controls fall short here because each one protects only the code path it was written for. A filter in one retriever does nothing for a second query engine, a cache or an agent tool that reads the same store.

    Where runtime policy enforcement complements the index

    Segmentation decides what can be found. Runtime enforcement decides what is allowed to happen on a given request. Evaluating the retrieval and the generation step against policy at runtime, rather than reviewing after the fact, catches the cases the index design did not anticipate: a request with the wrong purpose, a response that includes a restricted passage, or a tool call that tries to send retrieved content elsewhere. The outcomes are allow, redact or block, applied to the individual interaction.

    Trussed enforces policy in the execution path on individual interactions and tool calls across models, agents and tools, and generates audit-ready evidence from that enforcement, mapped to HIPAA. For a Part 2 deployment, the useful record per request is the role, the stated purpose, the partition and filters applied, what was retrieved, and the policy decision taken. That lets a team show afterward what was retrieved, by whom and under which policy, instead of reconstructing it from application logs. Trussed complements index design. It does not replace the segmentation, tagging and consent handling described above.

    Segmentation path for Part 2 content

    Classify at ingestion

    Tag records that identify a patient as having or having had a substance use disorder, with consent scope.

    Partition the index

    Place Part 2 content in a separate index, namespace or collection.

    Restrict retrieval

    Select the partition by role and purpose, then apply metadata filters.

    Enforce and evidence

    Evaluate each request against policy and keep a per-request record.

    Review your Part 2 retrieval design

    Walk through your index layout, query paths and evidence needs with a Trussed expert.

    Talk to an Expert
    Next step

    How does your AI governance program compare?

    See where your program has gaps in less than 2 minutes.