npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

llm-tool-parser

v0.0.4

Published

Universal LLM tool call extractor that normalizes messy outputs into a unified ToolCall format.

Readme

llm-tool-parser

A TypeScript utility for extracting and normalizing tool calls from large language model outputs.

It supports both native tool calling formats (OpenAI tool_calls, Claude tool_use, etc.) and “text-based tool calls” commonly produced by open-source or fine-tuned models.

The library converts inconsistent, streaming, or partially corrupted LLM outputs into a clean and unified ToolCall structure, making it easier to build reliable agent runtimes.

Key features

  • Supports multiple LLM ecosystems (OpenAI, Claude, DeepSeek, Qwen, etc.)
  • Extracts tool calls from raw text, JSON, XML, and hybrid formats
  • Handles streaming, trailing text, and malformed outputs
  • Normalizes all inputs into a unified ToolCall schema
  • Works with both structured tool calling and prompt-based agents

Live parse

Live parse: https://saber2pr.top/llm-tool-parser/

Simple usage

Examples below are based on src/parser.test.ts.

import { parseLlmToolCalls } from 'llm-tool-parser'

const text =
  '{"tool_calls":[{"tool_name":"fileRead","arguments":{"filePath":"/tmp/a.ts"}}]}'

const { content, toolCalls } = parseLlmToolCalls(text)

console.log(content)
console.log(toolCalls[0]?.name)
console.log(toolCalls[0]?.arguments)

You can also parse model outputs that contain extra text:

const text =
  '让我来查看一下\n{"tool_calls":[{"tool_name":"fileRead","arguments":{"filePath":"/a.ts"}}]}'

const { content, toolCalls } = parseLlmToolCalls(text)

console.log(content) // 让我来查看一下
console.log(toolCalls)
/**
[
  {
    id: 'call_1780567643675_6a8b',
    name: 'fileRead',
    arguments: { filePath: '/a.ts' }
  }
]
 */

And code-fenced JSON is supported too:

const text =
  '我来读取文件\n```json\n{"tool_calls":[{"tool_name":"fileRead","arguments":{"filePath":"/a.ts"}}]}\n```'

const { content, toolCalls } = parseLlmToolCalls(text)

Supported parsable formats

Based on all test cases in src/parser.test.ts, the parser currently supports these input patterns:

1. OpenAI-style tool_calls

{"tool_calls":[{"tool_name":"fileRead","arguments":{"filePath":"/tmp/a.ts"}}]}
  • single or multiple calls in one tool_calls array
  • multiple consecutive JSON blocks
  • JSON at the start with trailing text
  • plain text before the JSON block
  • JSON inside fenced code blocks

2. Single tool_name object

{"tool_name":"bash","arguments":{"command":"ls"}}

3. [tool_calls] marker + JSON objects

[tool_calls]{"tool":"grep","args":{"pattern":"hello"}}{"tool":"glob","args":{"pattern":"*.ts"}}

4. Action / Arguments text format

Action: fileRead
Arguments: {"filePath":"/tmp/test.ts"}

Also supports non-JSON arguments:

Action: grep
Arguments: foo

5. XML-style tool tags

<fileRead>{"filePath":"/tmp/a.ts"}</fileRead>
  • ignores non-tool tags like <thinking>
  • supports XML inside fenced code blocks

6. CLI log style [Called tools: ...]

● [Called tools: fileRead({"filePath":"/tmp/a.ts"})]

Also supports multiple calls:

● [Called tools: grep({"pattern":"foo"}), glob({"pattern":"*.ts"})]

7. OpenAI legacy function_call

{
  "function_call": {
    "name": "fileRead",
    "arguments": "{\"filePath\":\"/tmp/a.ts\"}"
  }
}

8. Claude tool_use

Content array form:

{
  "content": [
    {
      "type": "tool_use",
      "name": "fileRead",
      "input": {"filePath": "/tmp/a.ts"}
    }
  ]
}

Standalone form:

{
  "type": "tool_use",
  "name": "fileRead",
  "input": {"filePath": "/tmp/a.ts"}
}

9. OpenAI Responses API function_call

{
  "type": "function_call",
  "name": "fileRead",
  "arguments": "{\"filePath\":\"/tmp/a.ts\"}"
}

10. Simple tool + args object

{"tool":"fileRead","args":{"filePath":"/tmp/a.ts"}}

11. Root array of tool calls

[
  {"tool":"grep","args":{"pattern":"foo"}},
  {"tool":"glob","args":{"pattern":"*.ts"}}
]