Skip to main content
Zai is an LLM utility library that provides a clean, type-safe API for common AI operations. For example, you can use Zai’s methods to programmatically:
  • Extract structured data from an unstructured prompt
  • Verify a Boolean condition within a piece of content
  • Generate or summarize text
We recommend using Zai with the ADK and SDK to help process LLM inputs and outputs.
For a full list of available methods, check out the reference section.
Zai is imported by default in Execute Code Cards, Actions, and Hooks.

Installation

To install Zai for local development, run the following command in your terminal:
This also installs:

Quick start

To get started, import the libraries and create a new Client object using your Bot ID and Personal Access Token (PAT):
Then, create a new Zai instance and pass in the Client:
If you’re using Zai within Botpress Studio, you don’t need to create a new Zai instance—it’s already available globally as zai.

Usage examples

Here are some examples of how you can use Zai:

Get structured data from text

Use the extract method to get structured data from a plain piece of text:

Verify a condition

Use the check method to verify a condition against some input:

Filter an array

Use the filter method to filter elements of an array based on a condition:

Label content with categories

Use the label method to categorize content with predefined labels:

Rewrite text according to instructions

Use the rewrite method to transform text based on specific instructions:

Summarize long content

Use the summarize method to create concise summaries of lengthy text:

Generate text from prompts

Use the text method to generate content based on prompts:

Sort items based on criteria

Use the sort method to order items using natural language instructions:

Rate items on a scale

Use the rate method to evaluate items on a 1-5 scale:

Group items into categories

Use the group method to categorize items into groups:

Answer questions with citations

Use the answer method to answer questions from documents with source citations:

Modify files with natural language

Use the patch method to make surgical code edits across one or many files. Instead of regenerating entire files, it makes precise, minimal changes while preserving formatting and context: