LLMParser makes it easy for anyone to classify and extract structured data from text with large language models (LLMs). No prompt engineering or AI experience required.
While LLMs are extremely powerful, producing reliable JSON output is challenging.
LLMParser aims to solve this by enforcing a consistent JSON input and output format for classifying and extracting text with LLMs.
There are three main ways to use LLMParser:
To get started, install the package:
Then, import LLMParser, instantiate a new parser, and parse some text.
The LLMParser constructor takes an object with four fields:
Supply a categories array if you want to classify text.
Supply a fields array if you only want to extract fields from text.
If you want to classify and extract fields, you can add fields to a category.
The LLMParser instance has one method, parse, which takes two fields:
The result of the parse method is an object of type ParseResult.
The first use case we will go over is classifying text. For example, say we want to classify a job posting as either "Software Engineer" or "Head of Community."
Now let's put it all together and classify a job posting.
And here is our classification!
The categories array is how we tell our parser what categories to classify text into. Each category (type Category) has three fields:
If you want to classify and extract fields, you can populate the fields property on a category. Here's an example:
The next use case we will cover is extracting fields from text. For example, say we want to extract the job title, company name, and location from a job posting.
To do this we will instantiate a new LLMParser with the following fields:
Now let's put it all together and extract these fields from a job posting.
And here are our extracted fields!
The fields array is how we tell our parser what fields to extract from a document. Each field (type Field) has three fields:
Here's an example:
The last way to use LLMParser is to classify and extract fields. For example, say we want to classify a job posting as either "Software Engineer" or "Head of Community" and then extract the job title and location.
To do this we will instantiate a new LLMParser with the following categories:
Now let's put it all together and classify + extract data from a job posting.
And here are our results!