LLM Calls

Last updated: November 2026

In addition to one-shot and session-based interactions, the platform allows you to directly invoke LLMs inside JavaScript snippets. This enables highly flexible, programmatic use of LLMs within your coaching logic.

1 Overview

This feature is ideal for:

  • Dynamic message generation
  • Conditional logic based on LLM output
  • Backend-like processing within dialogs

2 Basic Usage

Step 1: Import the LLM Module

Add the following import at the top of your snippet:

//+llm

Step 2: Perform an LLM Call

Use the llm function with the following structure:

const result = llm(1, "Say hello to $participantName");
Parameter Description
First The LLM slot number (e.g., 1 for LLM1)
Second The text prompt sent to the model

ℹ️ LLM slot numbering matches the basic configuration of the coaching exactly: LLM1 = 1, LLM2 = 2, etc.

Response Format

LLM calls return a JSON object:

{
  "success": true,
  "message": "Hello John, how are you today?"
}
Field Description
success Indicates whether the call was successful
message The generated response from the LLM

3 Handling Responses

Instead of storing the full JSON object, extract only the relevant content and provide a fallback:

//+llm
const result = llm(1, "Say hello to $participantName");
const o = {
  llmResult: result.success ? result.message : "Hi $participantName!"
}
o

This ensures clean output for user-facing messages and graceful fallback handling if the call fails.

4 Returning Multiple Variables

One snippet can fill as many coaching variables as you need from a single LLM call. Ask the model to answer in JSON, parse the answer, and put every value into its own key of the result object — each key is written to its own $variable.

Example: Evaluate a goal with the SMART criteria

//+llm
const prompt = "Evaluate the goal '$goal' based on the SMART criteria. " +
               "Return a JSON object with the keys " +
               "'score' (integer 1-5), 'specific', 'measurable', 'achievable', " +
               "'relevant', 'timeBound' (booleans) and 'feedback' (string). " +
               "Return ONLY the raw JSON object, no markdown formatting."

const result = llm(1, prompt)

// Default values = fallback if the call or the parsing fails
const o = {
  smartStatus: "error",
  smartScore: 0,
  smartSpecific: false,
  smartMeasurable: false,
  smartAchievable: false,
  smartRelevant: false,
  smartTimeBound: false,
  smartFeedback: ""
}

if (result.success) {
  try {
    // Remove ```json fences in case the model adds them anyway
    const parsed = JSON.parse(result.message.replace(/```(json)?/g, "").trim())
    o.smartScore = Number(parsed.score) || 0
    o.smartSpecific = parsed.specific === true
    o.smartMeasurable = parsed.measurable === true
    o.smartAchievable = parsed.achievable === true
    o.smartRelevant = parsed.relevant === true
    o.smartTimeBound = parsed.timeBound === true
    o.smartFeedback = parsed.feedback || ""
    o.smartStatus = "success"
  } catch (e) {
    o.smartStatus = "parse error"
  }
}

o

This writes eight variables: $smartStatus, $smartScore, $smartSpecific, … $smartFeedback. Create each of them beforehand in the variables tab with the access setting "manageable by service". Booleans are stored as "true" / "false", numbers as plain numbers (see Writing Output Variables).

Alternative: one variable for the whole answer. If you do not need the values separately, store the parsed object in a single variable — it is saved as JSON:

const o = {
  smartEvaluation: parsed   // → $smartEvaluation contains the whole JSON object
}
o

Only the last expression counts. Exactly one result object is written back: the one at the very end of the script. A bare output in the middle of the script writes nothing, and no statement may follow the result object. Names are case-sensitive — o and O are two different things.

Check $smartStatus before you use the values. If the model does not return valid JSON, the snippet keeps the default values. Branch on the status variable in the next decision point to show a fallback message instead of an empty feedback.

5 Multiple LLM Calls in One Snippet

A snippet may call llm(...) more than once. The calls run one after another, so a later call can use the answer of an earlier one:

//+llm
const summary = llm(1, "Summarise this journal entry in one sentence: '$journalEntry'")

const tip = llm(1, "Give one short, encouraging tip for someone who wrote: " +
                   (summary.success ? summary.message : "'$journalEntry'"))

const o = {
  journalSummary: summary.success ? summary.message : "",
  journalTip: tip.success ? tip.message : "Keep going — every entry counts!"
}
o

Check success for every call separately and give each output its own fallback. Different calls may also use different LLM slots, e.g. llm(1, …) and llm(2, …).

Mind the 60-second limit. All calls of a snippet together must finish within the execution limit of 60 seconds — otherwise the snippet is stopped and no variable is written. If several values can come from the same question, prefer one call that returns JSON (see above) over several calls.

6 Using Variables in Prompts

You can dynamically insert coaching variables into prompts for personalised, context-aware responses:

const result = llm(1, "Say hello to $participantName");

7 System Prompt Override

By default, the platform uses a predefined system prompt (e.g., a helpful assistant persona). You can override this by supplying a custom system prompt as an additional parameter.

Syntax:

const result = llm(1, "Your custom system prompt", "Your user prompt");
Parameter Description
First LLM slot number
Second Custom system prompt
Third User prompt

The prompt should also provide as a second parameter the language (normally saved in $participantLanguage), e.g. "Answer in $participantLanguage", if the coaching language is not english.

Example:

//+llm
const result = llm(1, "Behave like you are a cat", "Say hello to $participantName");
const o = {
  llmResult: result.success ? result.message : "Hi $participantName!"
}

Example output:

8 Integration in Dialog Flow

A typical use case inside a coaching:

  1. User provides input (e.g., their name)
  2. A decision point triggers a JavaScript snippet
  3. The snippet performs an LLM call to generate dynamic content
  4. The result is stored in a variable
  5. The next message bubble displays the result

9 Best Practices

  • Always check result.success before using the output
  • Provide meaningful fallback messages for failed calls
  • Need several values? Ask for JSON and return one key per variable
  • Keep prompts clear and concise
  • Use system prompts to enforce a consistent personality or tone
  • Avoid overly complex logic inside prompts — keep snippets readable