Issue with Integrating NeMo Guardrails with LangChain and LangServe for Chatbot #209

Open
opened 2026-02-16 00:19:24 -05:00 by yindo · 0 comments
Owner

Originally created by @AnkurVera464221 on GitHub (Jul 10, 2024).

Hello, I am currently working on a Retrieval-Augmented Generation (RAG) chatbot using LangChain and LangServe. I am attempting to integrate NeMo Guardrails into this system but am encountering issues with the chat history format when deploying my chain using LangServe.

Here is the detailed setup and issue:

### Setup

  1. LangChain Chain:

I created a LangChain chain which works perfectly in the Python environment.
I deployed it using LangServe, and the input JSON body for input looks like this:
image

  1. NeMo Guardrails Integration:

Integrated NeMo Guardrails with the conversational_retireval_chain using the following code:

chain_with_guardrails = RunnableRails(config, runnable=conversation_chain, input_key="question", output_key="answer") return chain_with_guardrails

This worked well in the Python environment, with the following example running successfully:
chain_with_guardrails.invoke({ "question": "user question", "chat_history": [("Hi", "Hello!"), ("Whats...", "Anwer...)] })

### Issue
When deploying this with LangServe, I encountered the following issues:

{ "input": { "question": "What is its latest release??", "chat_history": [ ["Hi, I am Ankur", "Hello"], ["What is AMP Impact?", "AMP impact?"] ] }, "config": {}, "kwargs": {} }

Error Recieved:

Error while execution generate_bot_message: Unsupported chat history format: <class 'list'>. Full chat history: [['Hi, I am Ankur', 'Hello'], ['What is AMP Impact?', 'AMP impact?']]

Attempt to Change Chat History to Tuples:

Changing each pair in the chat history to tuples, which worked in the Python environment, resulted in JSON parsing issues as JSON does not support tuples.

Input JSON Body:

{ "input": { "question": "What is its latest release??", "chat_history": [ ("Hi, I am Ankur", "Hello"), ("What is AMP Impact?", "AMP impact?") ] }, "config": {}, "kwargs": {} }

Error Received:

{ "detail": [ "Invalid JSON body" ] }

Empty Chat History:

Note: The chain works perfectly when the chat history is empty.

Request
I would like to request guidance on how to properly format the chat history for compatibility with NeMo Guardrails when deploying using LangServe. If there is a specific format or a workaround that I am missing, please let me know. Additionally, if this is an issue with NeMo Guardrails, I would appreciate any fixes or updates.

Thank you for your assistance.

Best regards,

Originally created by @AnkurVera464221 on GitHub (Jul 10, 2024). Hello, I am currently working on a Retrieval-Augmented Generation (RAG) chatbot using LangChain and LangServe. I am attempting to integrate NeMo Guardrails into this system but am encountering issues with the chat history format when deploying my chain using LangServe. Here is the detailed setup and issue: **### Setup** 1. LangChain Chain: I created a LangChain chain which works perfectly in the Python environment. I deployed it using LangServe, and the input JSON body for input looks like this: ![image](https://github.com/NVIDIA/NeMo-Guardrails/assets/146097531/a2ea6be4-918d-48a0-90a3-d5ac904e37ca) 2. NeMo Guardrails Integration: Integrated NeMo Guardrails with the conversational_retireval_chain using the following code: `chain_with_guardrails = RunnableRails(config, runnable=conversation_chain, input_key="question", output_key="answer") return chain_with_guardrails ` This worked well in the Python environment, with the following example running successfully: `chain_with_guardrails.invoke({ "question": "user question", "chat_history": [("Hi", "Hello!"), ("Whats...", "Anwer...)] }) ` **### Issue** When deploying this with LangServe, I encountered the following issues: `{ "input": { "question": "What is its latest release??", "chat_history": [ ["Hi, I am Ankur", "Hello"], ["What is AMP Impact?", "AMP impact?"] ] }, "config": {}, "kwargs": {} } ` Error Recieved: `Error while execution generate_bot_message: Unsupported chat history format: <class 'list'>. Full chat history: [['Hi, I am Ankur', 'Hello'], ['What is AMP Impact?', 'AMP impact?']] ` Attempt to Change Chat History to Tuples: Changing each pair in the chat history to tuples, which worked in the Python environment, resulted in JSON parsing issues as JSON does not support tuples. Input JSON Body: `{ "input": { "question": "What is its latest release??", "chat_history": [ ("Hi, I am Ankur", "Hello"), ("What is AMP Impact?", "AMP impact?") ] }, "config": {}, "kwargs": {} } ` Error Received: `{ "detail": [ "Invalid JSON body" ] } ` Empty Chat History: **Note**: The chain works perfectly when the chat history is empty. **Request** I would like to request guidance on how to properly format the chat history for compatibility with NeMo Guardrails when deploying using LangServe. If there is a specific format or a workaround that I am missing, please let me know. Additionally, if this is an issue with NeMo Guardrails, I would appreciate any fixes or updates. Thank you for your assistance. Best regards,
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#209