PromptEngine Docs
Features

Variables & Parameters

Dynamic prompts with variable support

Understanding the Variable System in PromptEngine

The variable system in PromptEngine is designed to simplify the integration of dynamic content within your templates, making your development process more efficient and flexible. Here we will explore how variables are used, automatically detected, and validated within the engine.

Variable Syntax

Variables in PromptEngine are identified using the double curly braces syntax:

{{variable_name}}

This syntax allows you to quickly insert variables anywhere in your text templates in a readable and easy-to-manage way.

Automatic Parameter Detection

PromptEngine automatically detects variables within templates and lists them as parameters that need to be supplied. This feature ensures that you do not miss any required data when rendering templates.

Type Inference and Validation

PromptEngine infers the data type of variables based on initial input and validates data types on subsequent uses. This helps in maintaining consistency and reliability in data handling.

PropTypeDefault
string?
String
-
number?
Integer/Float
-
date?
Date
-

Using Complex Types

Handling complex data types such as arrays and JSON objects is crucial for modern applications.

Arrays can be used to pass a list of values. Use syntax like {{ variable_name }} where variable_name is an array.

Example: {{ user_ids }} might represent multiple user IDs passed to the engine.

JSON objects allow for structured data inputs. They need to be properly formatted as JSON strings.

Example: {{ user_details }} could be a JSON object containing user properties like name and email.

Default Values and Optional Parameters

You can define variables with default values or mark them as optional, enhancing template flexibility and error handling.

Define a Default Value

Include a default value in the variable definition to ensure that there is always a value available, reducing errors if no input is provided.

Syntax: {{variable_name=default_value}}

Marking Parameters as Optional

Optional parameters can be defined, implying that their absence will not prevent template rendering.

Indicate optional parameters by appending a question mark ?.

This documentation should provide a clear understanding of how to effectively use the variable system in PromptEngine, ensuring you leverage its full potential to create dynamic, robust templates for your applications.