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 objectsconst 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', ...]
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 الله leakP9999 - 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 }}
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.