CoolFace
Apppublic

Neeraj-Ch0udhary/llmguard-demo

sourceHugging Faceupdated 4mo agoView on Hugging Face
1likes
App README

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

LangChain Integration

python
from sdk.langchain_integration import PromptShieldChain
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o")

chain = PromptShieldChain(
    llm=llm.invoke,
    sources=your_rag_documents,
    session_id="user_123"
)

# Injection blocked, hallucination caught, memory stored — all in one call
response = chain.run(user_input)

Or use individual guards:

python
from sdk.langchain_integration import PromptShieldInput, PromptShieldOutput, PromptShieldMemory

# Block injections
shield = PromptShieldInput()
safe_input = shield.run(user_message)  # raises ValueError if injection detected

# Catch hallucinations  
output = PromptShieldOutput(sources=docs)
safe_response = output.run(llm_response)

# Persistent memory
memory = PromptShieldMemory(session_id="user_123")
memory.save("user wants a refund")
facts = memory.load("what does user want?")