Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/langchain-security-basics

@0d57af8
Run it yourself

Harden a LangChain 1.0 chain or LangGraph agent against prompt injection, tool abuse, PII leakage in traces, and secrets exfiltration — wrap user content in XML tags, enforce the tool allowlist via provider-native tool calling, redact PII in middleware upstream of cache and tracing, validate outputs with Pydantic, and lock down secrets behind a secret manager. Use when prepping for a security review, responding to an incident, building a multi-tenant SaaS, or writing a threat model. Trigger with "langchain security", "prompt injection defense", "langchain tool allowlist", "langchain PII redaction", "langchain secrets management".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/langchain-security-basics

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescompliance-posture.md

≈2.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Compliance Posture — GDPR / HIPAA / SOC2 Touchpoints

A LangChain app with real users has compliance obligations that a reviewer will ask about. This reference maps the three most common frameworks (GDPR, HIPAA, SOC2) to the LangChain 1.0 controls that actually satisfy them, and documents the provider safety-settings decisions and audit-log fields a security reviewer expects to see.

Scope

This is not legal advice. It is a practitioner's map from compliance requirements to LangChain configuration — intended to help you prepare for a review, not to replace a CISO, a privacy counsel, or an auditor.

GDPR — personal data in prompts and traces

Article Requirement LangChain mitigation
Art. 5(1)(c) — data minimization Only process personal data you need PII redaction middleware upstream of the LLM call; remove unused fields before prompt
Art. 5(1)(e) — storage limitation Define and enforce retention OTEL trace retention policy (≤ 30 days typical); cache TTL aligned; no prompts in long-term logs
Art. 15 — right of access Provide user's data on request Structured logs keyed by user_id; query interface returns prompts, responses, metadata
Art. 17 — right to erasure Delete user's data on request Scriptable deletion across OTEL store, cache, structured logs; provider data processor agreement includes deletion
Art. 28 — processors DPA with every third party Signed DPA with Anthropic, OpenAI, Google; listed in privacy notice
Art. 32 — security of processing Encryption at rest and in transit TLS for all provider calls (default); secrets in Secret Manager encrypted at rest
Art. 44 — cross-border transfers Legal basis for transfer outside EEA Provider DPA + SCCs; document data residency (e.g., Anthropic EU-region endpoint if available)

Practical GDPR controls for a LangChain app

  • Redact before LLM call. Presidio-style detector on email, phone, credit_card, ssn, person_name, location. Replace with tokens ([EMAIL_1]) so the model still gets structure.
  • Turn OTEL content capture off in EEA-user multi-tenant. OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false (P27). If you need debug traces, export to a separately-permissioned sink with shorter retention.
  • Right to erasure script. A deterministic deletion job that walks OTEL, cache, and structured logs keyed by user_id.
  • Consent surface. If the LangChain app is user-facing, the privacy notice names each provider and the purpose.

HIPAA — PHI in healthcare apps

Safeguard Requirement LangChain mitigation
§ 164.312(a)(1) — access control Unique user IDs, emergency access Per-tenant agent construction (see P33); audit log identifies the user for every call
§ 164.312(b) — audit controls Record who accessed what PHI Structured logs with {user_id, tenant_id, tool, args_redacted, response_summary, request_id}
§ 164.312(c)(1) — integrity Prevent improper alteration Output validation (Pydantic); canary token detection for injection
§ 164.312(e)(1) — transmission security Encrypt in transit TLS to providers; no raw HTTP
BAA Business Associate Agreement with each vendor Signed BAA with the provider — Anthropic, OpenAI, Google each have BAA programs. Verify your usage is in-scope.

HIPAA-specific LangChain decisions

  • Provider selection. Only use a provider with a signed BAA. Document the tier — Anthropic's BAA applies to the API, not the consumer Claude.ai product; same for OpenAI Enterprise.
  • Gemini safety settings. Medical prompts trip HARM_CATEGORY_MEDICAL at the default threshold (P65). Override to BLOCK_NONE for medical workloads, document the override in the compliance posture doc, and rely on your own PII redaction + output validation instead.
  • No prompts in OTEL. Even with a BAA, the less PHI in tooling the better. Keep OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false.
  • Minimum necessary. Don't feed the entire patient chart into a prompt. Retrieve the narrowest relevant context (RAG with per-patient filter).

SOC2 — Trust Services Criteria

SOC2 is about demonstrating you have controls and they work. For a LangChain app, the Trust Services Criteria map:

Criterion LangChain mitigation
Security (CC6) XML injection boundary + canary; tool allowlist via create_react_agent; secret manager + SecretStr
Availability (CC7) max_retries=2, circuit breakers, provider fallbacks (see langchain-sdk-patterns); rate limits (langchain-rate-limits)
Processing Integrity (CC7) Pydantic output validation; tool-arg deny-list; structured logging
Confidentiality (CC6, CC9) PII redaction middleware; OTEL content off in multi-tenant; per-tenant data isolation (P33)
Privacy (CC9) Same as GDPR — explicit consent, data minimization, deletion workflow

SOC2 evidence a reviewer expects

  • Policy documents. Acceptable use policy for LLM; prompt-injection response plan; incident response runbook.
  • Configuration artifacts. Terraform/Helm manifests showing Secret Manager bindings, IAM policies, network isolation.
  • Audit logs. Immutable log of every tool call, with tenant/user/ request_id, retained per policy (typically 1 year for SOC2 Type II).
  • Access reviews. Quarterly review of who has access to Secret Manager, OTEL backend, and the app's admin surface.

Provider safety settings — decision matrix

Provider Default When to override How to document
Anthropic No per-category safety toggle (provider moderates server-side) N/A — adjust via system prompt if needed Record system prompt version in compliance doc
OpenAI Moderation API available as a separate call Add moderation pre-call for user-facing; skip for internal Log moderation decision per request
Gemini HARM_BLOCK_THRESHOLD=BLOCK_MEDIUM_AND_ABOVE across all categories Medical / legal / security domains trip defaults (P65) Record override per category in compliance doc, example below
# compliance_posture.py — committed to the repo, reviewed quarterly
GEMINI_SAFETY_PROFILE = {
    "version": "2026-04-21",
    "rationale": "Medical record summarization — HARM_CATEGORY_MEDICAL default "
                 "rejects legitimate clinical content. Mitigations: PII "
                 "redaction middleware upstream, Pydantic output validation, "
                 "human-in-loop review for any output with a safety-flag rating.",
    "settings": {
        "HARM_CATEGORY_MEDICAL": "BLOCK_NONE",
        "HARM_CATEGORY_HARASSMENT": "BLOCK_MEDIUM_AND_ABOVE",
        "HARM_CATEGORY_HATE_SPEECH": "BLOCK_MEDIUM_AND_ABOVE",
        "HARM_CATEGORY_SEXUALLY_EXPLICIT": "BLOCK_LOW_AND_ABOVE",
        "HARM_CATEGORY_DANGEROUS_CONTENT": "BLOCK_MEDIUM_AND_ABOVE",
    },
    "review_cadence": "quarterly",
    "approver": "CISO",
}

Audit-log schema

Minimum fields a SOC2 / HIPAA reviewer will expect on every LLM call:

{
  "request_id": "01HXYZ...ULID",
  "timestamp": "2026-04-21T14:32:11Z",
  "tenant_id": "tenant-42",
  "user_id": "user-8821",
  "provider": "anthropic",
  "model": "claude-sonnet-4-6",
  "prompt_hash": "sha256:abc123...",
  "prompt_redacted": "[EMAIL_1] asked about [PERSON_1]'s order",
  "response_summary": "Provided order status for redacted user",
  "tool_calls": [
    {"name": "lookup_order", "args_hash": "sha256:...", "duration_ms": 42}
  ],
  "input_tokens": 420,
  "output_tokens": 180,
  "safety_profile_version": "2026-04-21",
  "canary_hit": false,
  "pii_redactions": {"email": 1, "person": 1}
}

The prompt_hash lets you prove (via hash comparison) that a specific prompt was or was not processed, without storing the raw content. The prompt_redacted field is optional — include only if your retention policy and legal basis support it.

Resources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides a comprehensive set of security best practices for LangChain 1.0 and LangGraph applications. It covers prompt injection defenses, secret management, PII redaction, tool allowlisting, and compliance posture. The identified prompt injection patterns are educational examples used to illustrate threats and demonstrate defensive coding techniques, posing no security risk to the user or system.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: MEDIUM · 1 issue

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
What it can do
Reads files Edits files Runs commands
Modelinherit
model
inherit
argument-hint
<chain-or-agent-path>
user-invocable
true
All 5 allowed tools
ReadWriteEditGrepBash(grep:*)
Other metadata
disable-model-invocation
false
version
2.7.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
[
  "saas",
  "langchain",
  "langgraph",
  "python",
  "langchain-1.0",
  "security",
  "prompt-injection",
  "pii",
  "owasp-llm"
]
compatibility
Designed for Claude Code

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/langchain-security-basics