Store Chat Messages & State Without Managing Infrastructure.Check Out DialogueDB
Skip to content

Default Included Parsers

String Parser

string The default parser. Doesn't really parse, it passes through the string response with no modification. Returns: string

ts
const parser = createParser("string");
This is an example input message.
This is an example input message.

Number Parser

number Extracts a number from the LLM response. Returns: number

ts
const parser = createParser("number");
42
The answer is 42.

Boolean Parser

boolean Parses a boolean value from the LLM response. Recognizes common truthy/falsy patterns like "true", "false", "yes", "no". Returns: boolean

ts
const parser = createParser("boolean");
true
Yes, that is correct.

String Extractor Parser

stringExtract Use this parser to ensure the response is one of many specific strings you define. This parser does not return the LLM's actual response, but works through the enum you provide and looks for a match. When it finds one, it returns the enum value, ensuring the response is exactly as expected.

Returns: string

Example Prompt:
You need to reply with one of three options. Either stop, go forward, turn left, turn right.

ts
const parser = createParser("stringExtract", {
  enum: ["stop", "go forward", "turn left", "turn right"],
});

Options:

OptionTypeDefaultDescription
enumstring[][]The list of allowed values to match against.
ignoreCasebooleanfalseWhen true, matching is case-insensitive.
go forward
Go Forward.

List to Array

listToArray Converts a list (separated by \n) to an array of strings. Returns: string[]

Example Prompt:
You need to reply with a list of test cases that should be written for the code I included below. You must reply in an unordered list.

ts
const parser = createParser("listToArray");
[
 "Should return the default name if the function argument is null or undefined",
 "Should return function's name if function has a name property",
 "Should return the correct name if function is bound to an object",
 "Should return the correct name if function is anonymous",
 "Should return the correct name if the function's source has additional space",
 "Should return empty string if function has no applicable name.",
]
- Should return the default name if the function argument is null or undefined
- Should return function's name if function has a name property
- Should return the correct name if function is bound to an object
- Should return the correct name if function is anonymous
- Should return the correct name if the function's source has additional space
- Should return empty string if function has no applicable name.

List to Key/Value[]

listToKeyValue Converts a list of key: value pairs (separated by newlines) to an array of key/value objects. Returns Array<{ key: string; value: string; }>

[{
    "key": "Getting Started",
    "value": "To get started, we need to..."
},{
    "key": "Setting Up Your Account",
    "value": "To set up your account, you need to..."
}]
Getting Started: To get started, we need to...
Setting Up Your Account: To set up your account, you need to...

Markdown Code Block

markdownCodeBlock Extracts the first code block from the LLM response, including the language identifier. If the response contains no code blocks, returns { code: "", language: "" }. For extracting all code blocks, see markdownCodeBlocks below. Returns: { code: string; language: string; }

ts
const parser = createParser("markdownCodeBlock");
{
    "code": "function add(a: number, b: number){\nreturn a + b;\n}",
    "language": "typescript"
}
Below is the generated code:

```typescript
function add(a: number, b: number){
    return a + b;
}
```

Markdown Code Blocks

markdownCodeBlocks Extracts all code blocks from the LLM response, returning them as an array. Use this when the response may contain multiple code blocks. For extracting only the first code block, see markdownCodeBlock above. Returns: Array<{ code: string; language: string; }>

ts
const parser = createParser("markdownCodeBlocks");
[{
    "code": "function add(a: number, b: number){\nreturn a + b;\n}",
    "language": "typescript"
},
{
    "code": "function subtract(a: number, b: number){\nreturn a - b;\n}",
    "language": "typescript"
}]
Below is the generated code:

```typescript
function add(a: number, b: number){
    return a + b;
}
```

And the next:

```typescript
function subtract(a: number, b: number){
    return a - b;
}
```

Replace String Template

replaceStringTemplate Runs Handlebars substitution on the LLM's output, using the executor's input attributes as template data. This lets the LLM return a template string that gets filled in with the original input variables before being returned to the caller.

Returns: string

ts
const parser = createParser("replaceStringTemplate");

Use case: The LLM generates a response containing placeholders, and the parser fills them in with known values from the executor input — useful for personalized messages, dynamic templates, or mail-merge patterns.

Hello Alice! Your order #12345 has shipped.
Hello {{name}}! Your order #{{orderId}} has shipped.
{ name: "Alice", orderId: "12345" }

List to JSON

listToJson Parses key:value lines (separated by newlines) into a single flat object. Each line becomes one property — the key is derived from the text before the first colon, and the value is the text after it. Keys are camelCased by default.

Returns: object (flat key-value pairs)

WARNING

This parser produces a single object, not an array. If the LLM output contains duplicate keys, later values overwrite earlier ones. If you need to preserve multiple records with the same keys, use listToKeyValue instead (which returns an array of { key, value } pairs).

Example Prompt:
Extract the following information. Reply only with: Color: the color\nName: the name\nType: the type

typescript
const parser = createParser("listToJson");

Options:

OptionTypeDefaultDescription
keyTransform"camelCase" | "preserve""camelCase"How to transform keys. "camelCase" converts keys like "First Name" to "firstName". "preserve" keeps the original key text (trimmed).
schemaJSONSchemaundefinedOptional JSON Schema to validate and enforce types on the output.
{
    "color": "red",
    "name": "apple",
    "type": "fruit"
}
Color: Red
Name: Apple
Type: Fruit

Choosing between listToJson and listToKeyValue:

ParserReturnsBest for
listToJson{ key: value, ... } (flat object)Extracting a fixed set of unique fields from a response
listToKeyValueArray<{ key, value }>Preserving order, handling duplicate keys, or iterating over pairs

JSON

json Parse an expected stringified json object or array into a valid object. Schema can be passed in to enforce schema and provide default values. Returns: object | array

ts
const parser = createParser("json");

Options:

OptionTypeDefaultDescription
schemaJSONSchemaundefinedOptional JSON Schema to validate and enforce types on the output. Use with defineSchema for full type inference.
{
    "name": "Greg",
    "age": "89"
}
\`\`\`json
{ "name": "Greg", "age": "89" }
\`\`\`

or

{ \"name\": \"Greg\", \"age\": \"89\" }

TIP

You still need to instruct the LLM to respond with a certain format, and the parser will turn that response into a data-type useful to your application.