Skip to main content

LangChain integrations for Pangea

Project description

langchain-pangea

Pangea's tools for LangChain provide AI security features to protect your applications and data. Using these tools you can:

  • Defend against prompt injection attacks.
  • Prevent the exposure of sensitive information, including:
    • Personally Identifiable Information (PII)
    • Protected Health Information (PHI)
    • Financial data
    • Secrets
    • Intellectual property
    • Profanity
  • Remove malicious content from inputs and outputs, such as IP addresses, domains, and URLs.
  • Monitor user inputs and model responses to support threat analysis, auditing, and compliance efforts.

Installation

pip install -U langchain-pangea

Tools

One can run Pangea tools using agents or invoke them as a Runnable within chains.

AI Guard

import os

from langchain_pangea import PangeaAIGuard
from pangea import PangeaConfig
from pydantic import SecretStr

pangea_ai_guard_token = SecretStr(os.getenv("PANGEA_AI_GUARD_TOKEN"))
pangea_config = PangeaConfig(domain=pangea_domain)
pangea_ai_guard_tool = PangeaAIGuard(token=pangea_ai_guard_token, config=pangea_config, recipe="pangea_llm_response_guard")

Agent

from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool

@tool
def search_tool(data):
    """Call to perform search"""

    return """
    47.84.32.175
    37.44.238.68
    47.84.73.221
    47.236.252.254
    34.201.186.27
    52.89.173.88
    """

tools = [search_tool, pangea_ai_guard_tool]

query = """
Hi, I am Bond, James Bond. I monitor IPs found in MI6 network traffic.
Please find me the most recent ones, you copy?
"""

system_message="Always use AI Guard before your final response to keep it safe for the user."

langgraph_agent_executor = create_react_agent(model, tools, state_modifier=system_message)

state = langgraph_agent_executor.invoke({"messages": [("human", query)]})

Chain

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

prompt = ChatPromptTemplate.from_messages([("human", "{input}")])

query = """
Hi, I am Bond, James Bond. I am looking for a job. Please write me a super short resume.

I am skilled in international espionage, covert operations, and seduction.

Include a contact header:
Email: j.bond@mi6.co.uk
Phone: +44 20 0700 7007
Address: Universal Exports, 85 Albert Embankment, London, United Kingdom
"""

chain = (
  prompt
  | pangea_ai_guard_tool
  | model
  | StrOutputParser()
)

Standalone

pangea_ai_guard_tool.run("Spam me at example@example.com")
pangea_ai_guard_tool.invoke("Take my SSN: 234-56-7890")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_pangea-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_pangea-0.1.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file langchain_pangea-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_pangea-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langchain_pangea-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f1704cca9b780ab62597002e81acd2b3c31b5c348dc5abae48843477809c487
MD5 921443c2b948a236570fa22df0fb7c2e
BLAKE2b-256 aa3fa42f21e82df83ac956cc77fecd5126fc3955a6e3623a3024e0099ff9e823

See more details on using hashes here.

File details

Details for the file langchain_pangea-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_pangea-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53f54a2fad0d8203e72e1e5d939a77e4a3dbfeaac912dc4a1f2ec2cb64949155
MD5 2c570db986eda68101e22e129bd3fdf7
BLAKE2b-256 e5509519734b0e3d0cd1ec3a6060481731197e0c3f828de67ef52d236b3e92ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page