# LangChain LLM return no output even when the returned context is not empty

**URL:** <https://community.neo4j.com/t/langchain-llm-return-no-output-even-when-the-returned-context-is-not-empty/66231>\
**Category:** Graph Academy\
**Created:** [February 9, 2024, 4:44am UTC](https://community.neo4j.com/t/langchain-llm-return-no-output-even-when-the-returned-context-is-not-empty/66231 "2024-02-09T04:44:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swatakit](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/swatakit/32/30586_2.png) [@swatakit](https://community.neo4j.com/u/swatakit)\
**Post date:** [February 9, 2024, 4:44am UTC](https://community.neo4j.com/t/langchain-llm-return-no-output-even-when-the-returned-context-is-not-empty/66231/1 "2024-02-09T04:44:24Z")

</div>

Hi

I used GraphQueryQAChain to query a graph database, got the non-empty context back but the llm kept refusing to process the context

![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/7/9/79468735d323fb24a9fb3683f677eefa9817c468.png)

my issue is the same as this one [cypher - Langchain neo4j integration return no result - Stack Overflow](https://stackoverflow.com/questions/77397307/langchain-neo4j-integration-return-no-result/77965927#77965927)

I tried one of the suggestions to set `return_direct=False` but this one throw the chain into loop

Has anyone ever had this problem

---

<div class="post-metadata">

**Author:** ![elena.kohlwey](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/elena.kohlwey/32/31033_2.png) [@elena.kohlwey](https://community.neo4j.com/u/elena.kohlwey)\
**Post date:** [March 14, 2024, 12:57pm UTC](https://community.neo4j.com/t/langchain-llm-return-no-output-even-when-the-returned-context-is-not-empty/66231/2 "2024-03-14T12:57:33Z")

</div>

Hi swatakit,

I had the same problem as you and also was struggling a lot since I could not find any proper answers to that. A hint on an additional prompt then brought the solution for me. Here is, what I found out and then did:

Within the CypherQAChain, there is a prompt template which tells the LLM what to do with the received context. It is set by default to a standard QA Prompt which you can find here: [langchainjs/langchain/src/chains/graph\_qa/prompts.ts at main · langchain-ai/langchainjs · GitHub](https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/graph_qa/prompts.ts) under `const CYPHER_QA_TEMPLATE`.  
Of course, this is very general to suit all kinds of answers / use cases. I guess that in your (and in my) case this was just not enough for the LLM to understand how to transform the context into a proper response and hence it replied "I don't know".

My solution now was to copy that QA prompt into my script, modify it so that it understands what the returned context in my queries might be and provide it to the CypherQAChain. Here is a short extract:

```auto
CYPHER_GENERATION_TEMPLATE = """ 
Some cypher template text and at the end:

Schema:
{schema}

Question:
{question}

Cypher Query:
"""

QA_PROMPT = """
Some qa template ...

Question: Which customers are associated with Avery H. Jackson?
Context:[{{'Customer': 'Devon Q. Allen'}}, {{'Customer': 'Quinn L. Davis'}}]
Helpful Answer: The customers Devon Q. Allen and Quinn L. Davis are associated with Avery H. Jackson.

Follow this example when generating answers.
If the provided information is empty, say that you don't know the answer.

Information:
{context}

Question: {question}
Helpful Answer:
"""

cypher_prompt = PromptTemplate.from_template(CYPHER_GENERATION_TEMPLATE)
qa_prompt = PromptTemplate.from_template(QA_PROMPT)

cypher_qa = GraphCypherQAChain.from_llm(
    llm,
    graph=graph,
    verbose=True,
    cypher_prompt=cypher_prompt,
    qa_prompt = qa_prompt
)

```

Remark: Don't forget to put double curly brackets ({{ and }}) into the context example part of your prompt or else you will get the `ValueError: Missing some input keys: {...}` error.

For me this solved my problem and the context is now correctly used for formulating an answer. I hope it solves your problem, too!

Regards,  
Elena

---

<div class="post-metadata">

**Author:** ![swatakit](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/swatakit/32/30586_2.png) [@swatakit](https://community.neo4j.com/u/swatakit)\
**Post date:** [March 19, 2024, 3:52am UTC](https://community.neo4j.com/t/langchain-llm-return-no-output-even-when-the-returned-context-is-not-empty/66231/3 "2024-03-19T03:52:42Z")

</div>

@elena.kohlwey thank you very much - it worked for me!
