## The problem

Issue run-llama/llama_index#13715 (closed, 23 comments): ### Bug Description getting `openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'` error when using [json chat store](https://docs.llamaindex.ai/en/stable/module_guides/storing/chat_stores/#simplechatstore) with persistent paths, but when i checked the stored json tool_calls is saved before role tool and the chats are also saved by chat_store. I am receiving this error in long chats but only when i am loading the chat store again for specific key, when i tested separately in wh

## The verified fix

Collaborator logan-markewich: this was a known bug in the chat-store memory handling  -  the memory buffer dropped the assistant/tool message pairs, so a 'tool' role message was sent to OpenAI without a preceding 'tool_calls' assistant message. Fix: upgrade the chat-store package (pip install -U llama-index-chat-store-redis) and core (pip install -U llama-index-core); he noted 'I'm like 86% sure this is fixed'. Related reporter tip: removing/trimming chat history can also restore working pairs since truncation can split tool_call pairs.