Skip to main content

PromptVariable

Types for prompt variables with modality definitions.

Overview

Variable types define dynamic content that can be injected into prompts, with support for multiple modalities.

PromptVariable

Prompt variable with name and modality.
interface PromptVariable {
  name: string;
  modality: VariableModality;
}
Properties:
  • name - Variable name (used as {{variable_name}} in prompts)
  • modality - Variable modality type (VariableModality)
Example:
import type { PromptVariable } from '@adaline/api';

const variables: PromptVariable[] = [
  { name: 'user_name', modality: 'text' },
  { name: 'company_name', modality: 'text' },
  { name: 'company_logo', modality: 'image' },
  { name: 'report', modality: 'pdf' },
  { name: 'external_data', modality: 'api' },
  { name: 'nested_prompt', modality: 'prompt' }
];
JSON:
[
  { "name": "user_name", "modality": "text" },
  { "name": "company_name", "modality": "text" },
  { "name": "company_logo", "modality": "image" },
  { "name": "report", "modality": "pdf" }
]

VariableModality

See the dedicated VariableModality page for full documentation. Variable modality type enumeration.
type VariableModality = 'text' | 'image' | 'pdf' | 'api' | 'prompt';
Values:
  • 'text' - Plain text content
  • 'image' - Image content (URL or base64)
  • 'pdf' - PDF document content
  • 'api' - External API data source
  • 'prompt' - Nested prompt reference
Example:
import type { VariableModality } from '@adaline/api';

const modality: VariableModality = 'text';

VariableValue

See the dedicated VariableValue page for full documentation. Variable value type, discriminated by modality. Used when providing values for prompt variables.
type VariableValue =
  | TextContent
  | ImageContent
  | PdfContent
  | ApiContent
  | PromptContent;
Example:
import type { VariableValue } from '@adaline/api';

// Text value
const textValue: VariableValue = {
  modality: 'text',
  value: 'John Doe'
};

// Image value
const imageValue: VariableValue = {
  modality: 'image',
  detail: 'auto',
  value: {
    type: 'url',
    url: 'https://example.com/logo.png'
  }
};

// PDF value
const pdfValue: VariableValue = {
  modality: 'pdf',
  value: {
    type: 'url',
    url: 'https://example.com/docs.pdf'
  },
  file: {
    name: 'user_guide.pdf',
    id: 'file_123'
  }
};

Using with Deployments

import { Adaline } from '@adaline/client';
import type { Deployment, PromptVariable } from '@adaline/api';

const adaline = new Adaline();

const deployment: Deployment = await adaline.getLatestDeployment({
  promptId: 'prompt_abc123',
  deploymentEnvironmentId: 'environment_abc123'
});

// Access variable definitions from the deployment
const variables: PromptVariable[] = deployment.prompt.variables;

variables.forEach(v => {
  console.log(`Variable: ${v.name}, Modality: ${v.modality}`);
});

Injecting Variables with injectVariables

The injectVariables utility substitutes {{variable_name}} placeholders in a prompt’s messages with actual values. It supports text, image, and PDF variable replacement.
import { injectVariables } from '@adaline/client';
import type { VariableValues } from '@adaline/client';

Signature

function injectVariables(options: {
  prompt: PromptSnapshot;
  variables: VariableValues;
}): PromptSnapshot;

type VariableValues = Record<string, string | ImageContent | PdfContent>;
The function returns a deep copy of the prompt — the original is never mutated. Placeholders without a matching variable are left as-is. Extra variables not referenced in the prompt are silently ignored.

Text Variables

import { Adaline, injectVariables } from '@adaline/client';

const adaline = new Adaline();

const deployment = await adaline.getLatestDeployment({
  promptId: 'prompt_abc123',
  deploymentEnvironmentId: 'environment_abc123'
});

const resolved = injectVariables({
  prompt: deployment.prompt,
  variables: {
    user_name: 'Alice',
    company_name: 'Acme Corp',
  },
});

Image Variables

When a text content item is exactly {{variable_name}}, it can be replaced with an ImageContent object:
import { injectVariables } from '@adaline/client';

const resolved = injectVariables({
  prompt: deployment.prompt,
  variables: {
    user_name: 'Alice',
    profile_pic: {
      modality: 'image',
      detail: 'auto',
      value: { type: 'url', url: 'https://example.com/alice.png' },
    },
  },
});

PDF Variables

Same pattern as image — replace a whole {{variable_name}} placeholder with a PdfContent:
import { injectVariables } from '@adaline/client';

const resolved = injectVariables({
  prompt: deployment.prompt,
  variables: {
    report: {
      modality: 'pdf',
      value: { type: 'url', url: 'https://example.com/report.pdf' },
      file: { name: 'report.pdf', id: 'file_abc123' },
    },
  },
});
Image and PDF variables can only replace a text content item whose entire value is {{variable_name}}. If the placeholder is embedded in larger text (e.g., "See: {{pic}}"), it is left as-is because an image or PDF cannot be embedded inside a string.

Complete Example

import { Adaline, injectVariables } from '@adaline/client';
import OpenAI from 'openai';

const adaline = new Adaline();
const openai = new OpenAI();

const deployment = await adaline.getLatestDeployment({
  promptId: 'prompt_abc123',
  deploymentEnvironmentId: 'environment_abc123'
});

// Inspect available variables
deployment.prompt.variables.forEach(v => {
  console.log(`${v.name} (${v.modality})`);
});

// Inject variable values
const resolved = injectVariables({
  prompt: deployment.prompt,
  variables: { user_name: 'Alice' },
});

// Use resolved prompt with your provider
const response = await openai.chat.completions.create({
  model: resolved.config.model,
  messages: [...],  // Build from resolved.messages
  temperature: resolved.config.settings?.temperature,
});