Skip to main content
This guide walks you through using wobble-bibble to retrieve translation prompts and validate LLM output.

Prerequisites

Make sure you have wobble-bibble installed:
npm install wobble-bibble

Get translation prompts

1

Import prompt functions

Start by importing the prompt access functions:
import { getPrompt, getPrompts, getPromptIds } from 'wobble-bibble';
2

Retrieve a specific prompt

Get a stacked prompt (master + specialized addon) by ID:
// Get the Hadith prompt (strongly typed)
const hadithPrompt = getPrompt('hadith');

console.log(hadithPrompt.id);        // 'hadith'
console.log(hadithPrompt.name);      // 'Hadith'
console.log(hadithPrompt.isMaster);  // false
console.log(hadithPrompt.content);   // Master + Hadith addon combined
The content field contains the full prompt text ready to send to your LLM.
3

List available prompts

Get all available prompts or just their IDs:
// Get all prompts as StackedPrompt objects
const allPrompts = getPrompts();
console.log(allPrompts.length); // 8 prompts

// Get just the prompt IDs (useful for dropdowns)
const ids = getPromptIds();
// ['master_prompt', 'hadith', 'fiqh', 'tafsir', 'fatawa', ...]

Validate LLM output

1

Import validation function

Import the unified validation function:
import { validateTranslationResponse } from 'wobble-bibble';
import type { Segment } from 'wobble-bibble';
2

Prepare source segments

Create an array of source segments with IDs and Arabic text:
const segments: Segment[] = [
  {
    id: 'P1234',
    text: 'قال رسول الله صلى الله عليه وسلم: إنما الأعمال بالنيات'
  },
  {
    id: 'P1235',
    text: 'وإنما لكل امرئ ما نوى'
  }
];
Each segment must have an id (string) and text (Arabic source).
3

Validate the LLM response

Pass the segments and LLM output to the validator:
const llmOutput = `P1234 - The Messenger of Allah ﷺ said: Actions are by intentions.
P1235 - And every person will have what they intended.`;

const result = validateTranslationResponse(segments, llmOutput);

console.log(result.parsedIds);  // ['P1234', 'P1235']
console.log(result.errors);      // []
If validation passes, errors will be an empty array.
4

Handle validation errors

When errors are detected, each includes precise location data:
const badOutput = `P1234 - Translation with الله leak
P9999 - Invented ID`;

const result = validateTranslationResponse(segments, badOutput);

if (result.errors.length > 0) {
  for (const error of result.errors) {
    console.log(error.type);       // 'arabic_leak' or 'invented_id'
    console.log(error.message);    // Human-readable description
    console.log(error.matchText);  // Exact text that failed
    console.log(error.range);      // { start: 14, end: 18 }
    console.log(error.id);         // Segment ID if applicable
  }
}

Configure validation thresholds

Customize validation behavior with optional configuration:
const result = validateTranslationResponse(segments, llmOutput, {
  config: {
    allCapsWordRunThreshold: 5  // Trigger error after 5 consecutive ALL CAPS words
  }
});
The validator automatically normalizes line endings and splits merged markers before validation.

Working with validation error types

Use the error type info object for UI display:
import { VALIDATION_ERROR_TYPE_INFO } from 'wobble-bibble';

const description = VALIDATION_ERROR_TYPE_INFO.arabic_leak.description;
// 'Arabic script was detected in output (except ﷺ).'
Available error types:
Error typeDescription
invalid_marker_formatMalformed segment marker (wrong ID shape or missing content)
no_valid_markersNo valid “ID - …” markers found in response
newline_after_idUsed “ID -\nText” instead of “ID - Text”
duplicate_idSame segment ID appears multiple times
invented_idResponse contains ID not in source corpus
missing_id_gapGap detected between consecutive IDs
collapsed_speakersSpeaker labels appear mid-line instead of new line
truncated_segmentSegment appears truncated (”…”, “[INCOMPLETE]“)
arabic_leakArabic script detected (except ﷺ)
empty_parenthesesExcessive ”()” patterns (failed transliterations)
length_mismatchTranslation too short relative to Arabic source
all_capsALL CAPS “shouting” detected
multiword_translit_without_glossMulti-word transliteration without parenthetical gloss

Format segments for prompts

Format segments for LLM input with the utility function:
import { formatExcerptsForPrompt } from 'wobble-bibble';

const segments: Segment[] = [
  { id: 'P1', text: 'نص عربي...' },
  { id: 'P2', text: 'نص آخر...' }
];

const promptText = getPrompt('hadith').content;
const fullPrompt = formatExcerptsForPrompt(segments, promptText);

// Send fullPrompt to your LLM
This formats each segment as ID - Text and combines them with the prompt.

Next steps

API reference

Explore all available functions and types

Validation rules

Deep dive into validation rules and error handling

Build docs developers (and LLMs) love