# Ghost Message in chat History

**URL:** <https://community.n8n.io/t/ghost-message-in-chat-history/92341>\
**Category:** Questions\
**Created:** [March 25, 2025, 1:47am UTC](https://community.n8n.io/t/ghost-message-in-chat-history/92341 "2025-03-25T01:47:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan\_thorpe](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/stefan_thorpe/32/59023_2.png) [@stefan\_thorpe](https://community.n8n.io/u/stefan_thorpe)\
**Post date:** [March 25, 2025, 1:47am UTC](https://community.n8n.io/t/ghost-message-in-chat-history/92341/1 "2025-03-25T01:47:33Z")

</div>

## Describe the problem/error/question

I have a slack chatbot. That works great for the most part however I’m struggling to make it context aware.

Follow on threads load chat history from postgress. However, previous Ai agents appear to be “adding” 2 undefined messages to the chat history. On loading the history Anthropic/The Ai Agent states “Cannot read properties of undefined (reading ‘map’)”

The root of the issue appears to be in previous executions receiving the following message

```auto
"formatting_instructions": "IMPORTANT: For your response to user, you MUST use the `format_final_json_response` tool with your complete answer formatted according to the required schema. Do not attempt to format the JSON manually - always use this tool. Your response will be rejected if it is not properly formatted through this tool. Only use this tool once you are ready to provide your final answer.",
    "chat_history": [
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "oo7-3658",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],

```

I’ve not seen the empty AI or Human message without the Format response message.

## What is the error message (if any)?

Cannot read properties of undefined (reading ‘map’)  
or For your response to user, you MUST use the `format_final_json_response`

## Information on your n8n setup

- _n8n version : 1.84.1_
- _Database: Postgres_
- _n8n EXECUTIONS\_PROCESS : Runners Enabled??_
- _Running n8n : Docker, Helm Kube_

---

<div class="post-metadata">

**Author:** ![stefan\_thorpe](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/stefan_thorpe/32/59023_2.png) [@stefan\_thorpe](https://community.n8n.io/u/stefan_thorpe)\
**Post date:** [March 25, 2025, 1:52am UTC](https://community.n8n.io/t/ghost-message-in-chat-history/92341/2 "2025-03-25T01:52:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![stefan\_thorpe](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/stefan_thorpe/32/59023_2.png) [@stefan\_thorpe](https://community.n8n.io/u/stefan_thorpe)\
**Post date:** [March 27, 2025, 11:12pm UTC](https://community.n8n.io/t/ghost-message-in-chat-history/92341/3 "2025-03-27T23:12:36Z")

</div>

I add a node that executes a postgres query deleting the ghost messages. It’s a very ugly work around.

```auto
DELETE FROM n8n_chat_histories
WHERE 
  (message::jsonb->'kwargs'->>'content' IS NULL)
  AND (message::jsonb->>'content' IS NULL);

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [June 25, 2025, 11:13pm UTC](https://community.n8n.io/t/ghost-message-in-chat-history/92341/4 "2025-06-25T23:13:14Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
