Nirmos
Prompt management

Test prompt content

Distinguish local preview simulation from real model inference.

Use a configured server client and the permissions required by the selected operation. A simulated preview is useful for inspecting substitutions; evaluate a saved version against real cases before relying on output quality.

Model names beginning with configured/ are placeholders. Replace them with an accessible provider-qualified identifier from model discovery. The snippets reuse the server client from the quickstart.

Simulate a preview

Use an existing organization-owned prompt ID. prompts.preview is a mocked control-plane simulation: no external model is called. It estimates/randomizes metrics and does not prove provider availability, quality, quota or latency.

variablesJson is a JSON string encoding an array, for example [{"name":"customerName","type":"string","value":"Asha"}]. The simulator consumes name and string value; type is optional and ignored. An object such as {"customerName":"Asha"} is rejected as "Invalid variables format." Use simple {{customerName}} tokens; this simulator is separate from the managed renderer's whitespace/dotted-path/type validation contract.

modelSettingsJson encodes an object with model, optional provider, temperature, maxTokens and topP. Supply all numeric settings even though the current parser checks only that an object was supplied. Successful parsing is not full settings validation. Do not send these as nested request objects.

import { APIError } from "@nirmos/sdk";
function previewObject(value: unknown): Record<string, unknown> {
  return value !== null && typeof value === "object" && !Array.isArray(value)
    ? value as Record<string, unknown> : {};
}
try {
  const result = await nirmos.prompts.preview("prompt-id", {
    systemPrompt: "Help {{customerName}}.", userPrompt: "Write a greeting.",
    variablesJson: JSON.stringify([{ name: "customerName", type: "string", value: "Asha" }]),
    modelSettingsJson: JSON.stringify({ model: "configured/chat-model", temperature: 0.2, maxTokens: 100, topP: 1 }),
  });
  const preview = previewObject(previewObject(result).preview);
  if (preview.success === false) {
    throw new Error(typeof preview.error === "string" ? preview.error : "Preview application failure");
  }
  if (preview.status !== "success") throw new Error("Unexpected preview response");
  const response = previewObject(preview.response);
  console.log(response.content); // Mocked content, not a provider response.
} catch (error) {
  if (error instanceof APIError) {
    console.error({ status: error.status, code: error.code, requestId: error.requestId });
  }
  throw error; // Includes application failures and network/local failures.
}

After SDK decoding, success is { preview: { status: "success", request, response, metrics, timestamp, id } }, not preview.success: true. Application failures resolve as { preview: { success: false, error, latencyMs: 0 } }. Non-2xx errors (missing prompt, permissions, malformed outer body) reject with an API error. Check both application and HTTP failures. structuredOutputJson, when used, separately encodes structured-output config; invalid JSON is currently ignored, so validate it in your application.

Use prompts.test below for real provider inference, with gateway permission, configured credentials and quota. It uses success on the result and may incur provider cost; never infer its behavior from mocked preview metrics.

Execute a test request

const result = await nirmos.prompts.test({
  selectedModel: "configured/chat-model",
  messages: [{ role: "user", contentBlocks: [{ type: "text", text: "Write a support greeting." }] }],
  temperature: 0.2,
  maxTokens: 100,
});
if (!result.success) throw new Error(result.error ?? "Prompt test failed");
console.log(result.data?.output, result.meta?.request_id);

test uses runtime and returns its declared success, optional data, error, usage and meta fields. It is distinct from management preview (JSON-string settings) and compile (content-block variable compilation). A resolved promise with success: false is an application failure; HTTP status handling alone is insufficient.

Evaluation before release · Prompt reference

On this page