Skip to content

convertToFormattedString doesn't properly format non-primitive tool arguments #9504

@LiteracyFanatic

Description

@LiteracyFanatic

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

    console.log(new AIMessage({
      content: "Here is the result.",
      tool_calls: [
        {
          name: "someTool",
          args: { stringArg: "someFile", objectArg: { key: "someValue" } }
        }
      ]
    }).toFormattedString());

// ================================== Ai Message ==================================
// Tool Calls:
//   someTool (undefined)
//  Call ID: undefined
//   Args:
//     stringArg: someFile
//     objectArg: [object Object]

// Here is the result.

Error Message and Stack Trace (if applicable)

No response

Description

When I format messages with toFormattedString() I would expect to see all arguments formatted in a readable way. Instead, only primitive values are formatted and objects are displayed as [object Object].

System Info

npm info langchain

[email protected] | MIT | deps: 5 | versions: 348
Typescript bindings for langchain
https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain/

keywords: llm, ai, gpt3, chain, prompt, prompt engineering, chatgpt, machine learning, ml, openai, embeddings, vectorstores

dist
.tarball: https://registry.npmjs.org/langchain/-/langchain-1.1.1.tgz
.shasum: 6f0392a9971f16d69264d4e8ff4a1085b1c96136
.integrity: sha512-z7cOFhLOzbu/lRlIE8GZ5rlfi7obvvHThhMdts1KsUBusJmWLmh1Yik28MHYzJRXclUbqs4u/9D2yNmr36wf0A==
.unpackedSize: 2.3 MB

dependencies:
@langchain/langgraph-checkpoint: ^1.0.0 langsmith: ~0.3.74 zod: ^3.25.76 || ^4
@langchain/langgraph: ^1.0.0 uuid: ^10.0.0

maintainers:

dist-tags:
latest: 1.1.1 alpha: 1.0.0-alpha.9
next: 1.0.0-alpha.9 tag-for-publishing-older-releases: 0.2.20

published 22 hours ago by GitHub Actions [email protected]

node --version
v25.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions