DEV Community

Wu Long
Wu Long

Posted on • Originally published at blog.wulong.dev

When [object Object] Is All Your Agent Hears

Your user sends a perfectly normal WhatsApp message. Your agent receives [object Object]. No error. No warning. Just... five words of garbage where their question used to be.

This is #52464, and it is one of those bugs that makes you question everything you know about JavaScript.

The Setup

OpenClaw's WhatsApp integration uses Baileys, which hands you raw message objects. Somewhere between Baileys and the LLM, there's a sanitization function:

function sanitizeChatSendMessageInput(message) {
    const normalized = message.normalize("NFC");
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Looks fine, right? message is a string, .normalize() returns a normalized string. Ship it.

Except sometimes message isn't a string.

The Coercion

When Baileys passes the raw message structure, JavaScript does not throw. It does something worse: it cooperates.

const message = { conversation: "Hello, help me" };
message.normalize("NFC");
// → "[object Object]"
Enter fullscreen mode Exit fullscreen mode

JavaScript calls .toString() first. Object.prototype.toString() returns "[object Object]". Then .normalize("NFC") runs on that string. No error. No crash. The function happily returns sanitized garbage.

Why It Matters for AI Agents

In a normal web app, [object Object] shows up on screen and someone files a bug. In an AI agent system, the LLM processes the garbage and produces a plausible-sounding response. A crash is obvious. But an LLM confidently responding to [object Object] as if it were a real question? That's invisible.

The Fix

One typeof check:

function sanitizeChatSendMessageInput(message) {
    if (typeof message !== "string") {
        if (message && typeof message === "object") {
            message = message.text || message.body
                   || message.conversation || message.content
                   || String(message);
        } else {
            return { ok: false, error: "message must be a string" };
        }
    }
    const normalized = message.normalize("NFC");
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Or better: fix the channel handler to always extract text from the Baileys object before calling sanitization.

Full analysis on my blog: When [object Object] Is All Your Agent Hears

Issue: openclaw/openclaw#52464

Top comments (0)