LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph-sdkencryptiontypesContextHandler
    Attribute●Since v0.2

    ContextHandler

    Copy
    ContextHandler = Callable[['BaseUser', EncryptionContext], Awaitable[dict[str, typing.Any]]]
    View source on GitHub

    Parameters

    NameTypeDescription
    user*unknown

    The authenticated user (from Starlette's AuthenticationMiddleware)

    ctx*unknown

    Current encryption context with metadata from X-Encryption-Context header

    Handler for deriving encryption context from authenticated user info.

    Note: Must be an async function as it may involve I/O operations.

    The context handler is called once per request in middleware (after auth), allowing encryption context to be derived from JWT claims, user properties, or other auth-derived data instead of requiring a separate X-Encryption-Context header.

    The return value becomes ctx.metadata for subsequent encrypt/decrypt operations and is persisted with encrypted data for later decryption.

    Note: ctx.model and ctx.field will be None in context handlers since the handler runs once per request before any specific model/field is known.