All posts

Segregation of Duties for LangChain

When a LangChain application runs with a single service account, every prompt, data fetch, and model call shares the same privileges, violating segregation of duties. A mis‑crafted prompt can exfiltrate customer data, and a compromised key can be used to alter downstream systems. The financial and reputational cost of such unchecked activity quickly outweighs any convenience gained from a monolithic credential. Most teams deploy LangChain by installing the library on a server, configuring an AP

Free White Paper

DPoP (Demonstration of Proof-of-Possession): The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

When a LangChain application runs with a single service account, every prompt, data fetch, and model call shares the same privileges, violating segregation of duties. A mis‑crafted prompt can exfiltrate customer data, and a compromised key can be used to alter downstream systems. The financial and reputational cost of such unchecked activity quickly outweighs any convenience gained from a monolithic credential.

Most teams deploy LangChain by installing the library on a server, configuring an API key for the LLM provider, and letting the code reach databases, storage buckets, or internal APIs directly. The same identity that writes prompts also reads from production tables, updates configuration, and invokes external services. Because the connection is direct, there is no way to tell which part of the chain performed a particular action, nor to enforce that only approved prompts can touch sensitive data.

This reality makes segregation of duties – the practice of separating responsibilities so that no single identity can both initiate and approve a critical operation – virtually impossible. Auditors ask for evidence that a developer who writes prompt logic cannot also execute privileged data queries, but the raw LangChain flow provides no audit trail, no inline data protection, and no approval workflow.

Why the usual identity setup is insufficient

Introducing a non‑human identity (a service account or OIDC token) and limiting its scope is a necessary first step. It tells the platform who is making the request and can reduce the blast radius of a stolen secret. However, the request still travels straight from the LangChain process to the target service. The gateway that carries the traffic does not examine the payload, does not mask returned fields, and does not require a human to approve a risky operation. In other words, the setup establishes who can act, but it does not enforce what they are allowed to do.

Without a control point on the data path, the following gaps remain:

  • There is no record of which prompt generated a particular database query.
  • Sensitive response fields (for example, credit‑card numbers) are returned unfiltered.
  • Any request that should be reviewed – such as a prompt that writes to a production table – proceeds without oversight.
  • Replay of a session to investigate an incident is impossible because the traffic was never captured.

hoop.dev as the enforcement layer

hoop.dev is a Layer 7 gateway that sits between the LangChain runtime and every downstream target – LLM APIs, databases, internal HTTP services, or SSH endpoints. The gateway is deployed inside the same network as the resources it protects, and an agent runs locally to terminate the connection on behalf of the caller.

Setup – Identity providers such as Okta, Azure AD, or Google Workspace issue OIDC tokens. hoop.dev validates those tokens, extracts group membership, and maps each user to a set of permissions. Service accounts used by automated agents receive their own tokens, keeping human and machine identities distinct.

The data path – All LangChain calls are routed through hoop.dev. Because the gateway terminates the protocol (HTTP for LLM APIs, PostgreSQL for database queries, SSH for remote commands), it can inspect each request before it reaches the target.

Continue reading? Get the full guide.

DPoP (Demonstration of Proof-of-Possession): Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.

Enforcement outcomes – hoop.dev enforces segregation of duties in three concrete ways:

  • It records every request and response, attaching the caller’s identity, timestamp, and policy decision. The log can be replayed to answer “who asked what and when.”
  • It masks sensitive fields in responses according to policy rules, so downstream analysts never see raw PII or secrets.
  • It requires just‑in‑time approval for operations that cross a duty boundary, such as a prompt that writes to a production database. The request is held at the gateway until an authorized reviewer grants permission.

Because hoop.dev is the only point that can block, mask, or approve, the enforcement outcomes exist solely because the gateway sits in the data path. Removing hoop.dev would revert the system to the original, unprotected state.

Applying the model to a LangChain pipeline

Consider a typical pipeline that extracts customer data, enriches it with an LLM, and writes a summary back to a CRM table. With hoop.dev in place, the pipeline can be split into two roles:

  1. Prompt engineer – Holds a token that permits read‑only access to the source database and can invoke the LLM, but cannot write to the CRM.
  2. Data steward – Holds a token that permits write access to the CRM table but cannot call the LLM directly.

When the prompt engineer’s code reaches the LLM, hoop.dev records the call and masks any returned identifiers. When the code attempts to write the summary, hoop.dev detects that the caller lacks write permission and either blocks the request or routes it to a data steward for approval. The entire session is captured, providing an audit trail that satisfies compliance auditors.

Getting started

Deploy the gateway using the getting‑started guide. Define connection objects for the LLM provider and the target database, then map your OIDC groups to the appropriate policies. The learn section contains detailed examples of policy definitions for masking and just‑in‑time approvals.

All of this is open source and MIT licensed, so you can extend the enforcement logic to match the exact duties required by your organization.

FAQ

Does hoop.dev replace my existing identity provider?

No. hoop.dev consumes tokens from your IdP and uses them to make authorization decisions. It does not store or manage user credentials.

Can I use hoop.dev with existing LangChain code without changes?

Yes. The gateway works with standard clients (HTTP, PostgreSQL, SSH, etc.). Your LangChain code continues to call the same endpoints; hoop.dev intercepts the traffic transparently.

What happens if a request is denied?

The gateway returns a clear denial response to the caller. The event is logged, and the denial can be reviewed later for policy tuning.

Explore the open‑source repository on GitHub to see how the project is built and to contribute.

Open source

Save the open-source gateway for agent data access

Hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.

Star and save the repo →More posts