
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
llmatch-js
Advanced tools
A JavaScript library for invoking LLMs and matching their responses with patterns
A JavaScript library for invoking LLMs and matching their responses with patterns. This is a JavaScript port of the Python llmatch package.
npm install llmatch-js
const { llmatch } = require('llmatch-js');
import { ChatLLM7 } from "langchain-llm7";
// Initialize your LLM client
const chat = new ChatLLM7()
// Create a wrapper for the LLM that matches the expected interface
const llm = {
invoke: async (messages, options = {}) => {
const response = await chat.invoke({
messages: messages,
...options
});
return {
content: response.content,
raw: response
};
}
};
// Use llmatch to extract structured data
async function extractJson() {
const result = await llmatch({
llm,
query: "Generate a JSON object with information about a random book.",
pattern: /```json\n([\s\S]*?)```/,
verbose: true
});
if (result.success) {
// Parse the extracted JSON
const bookData = JSON.parse(result.extractedData[0]);
console.log("Book data:", bookData);
} else {
console.error("Failed to extract JSON:", result.errorMessage);
}
}
extractJson().catch(console.error);
Main function that invokes an LLM and matches the response against a pattern.
| Parameter | Type | Default | Description |
|---|---|---|---|
llm | Object | null | An already initialized instance of the LLM client |
query | string | "Extract relevant data." | The main query or instruction for the LLM |
pattern | string | RegExp | /(.*?)/s | A regex string or compiled RegExp object |
context | string | null | Optional additional text to provide context to the LLM |
promptTemplate | string | "{query}\n\n{context}\nWrite the answer in the next format: {format}" | Template string |
maxRetries | number | 15 | Maximum number of attempts to make |
initialDelay | number | 1.0 | Seconds to wait before the first retry |
backoffFactor | number | 1.5 | Multiplier for the delay between retries |
verbose | boolean | false | If true, prints detailed logs of the process |
passThrough | Object | {} | Additional parameters to pass to the LLM invocation |
The function returns a Promise that resolves to an object with the following properties:
| Property | Type | Description |
|---|---|---|
success | boolean | True if a valid response was found |
extractedData | Array | null | Array of strings matching the pattern (capturing groups), or null if no pattern was provided or matched |
finalContent | string | null | The content of the last successful or final failed LLM response |
retriesAttempted | number | Number of retries made (0 means success on first try) |
errorMessage | string | null | Description of the error if success is false |
rawResponse | any | The raw response object from the last LLM call |
Your LLM client should implement the following interface:
interface LLMClient {
invoke(messages: Array<{role: string, content: string}>, options?: any): Promise<{
content: string;
[key: string]: any;
}>;
}
MIT
FAQs
A JavaScript library for invoking LLMs and matching their responses with patterns
We found that llmatch-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.