@lukefryer4/stco-prompt-builder
v1.0.0
Published
A lightweight, type-safe builder for the **STCO Prompt Engineering Framework**.
Readme
@lukefryer4/stco-prompt-builder
A lightweight, type-safe builder for the STCO Prompt Engineering Framework.
Note: This package is a structural utility for formatting and validating STCO prompts in TypeScript/JavaScript. To generate, grade, and automatically test these prompts using our proprietary AI algorithms, visit the official visual builder at AI Prompt Architect.
What is STCO?
STCO (System, Task, Context, Output) is a deterministic framework designed to drastically reduce LLM hallucinations and standardise prompt engineering across large enterprise teams.
Instead of writing unstructured paragraphs to language models, you break your prompt into four explicit components. This library provides the type-safety and formatting engine to do exactly that in your codebase.
Installation
npm install @lukefryer4/stco-prompt-builder
# or
pnpm add @lukefryer4/stco-prompt-builder
# or
yarn add @lukefryer4/stco-prompt-builderUsage
1. Type-Safe Prompt Definitions
Define your prompts with absolute type safety in your codebase.
import { STCOPrompt } from '@lukefryer4/stco-prompt-builder';
const prompt: STCOPrompt = {
system: 'You are a senior React developer and performance expert.',
task: 'Refactor the provided component to reduce unnecessary re-renders.',
context: 'We are using React 18, Next.js App Router, and TailwindCSS.',
output: 'Provide the complete refactored code block with brief inline comments.'
};2. Building the Prompt
Compile your structured prompt into a unified string formatted perfectly for LLMs (GPT-4, Claude 3, Gemini, etc.).
import { buildPrompt } from '@lukefryer4/stco-prompt-builder';
// Formats with clean Markdown headers (### System, ### Task, etc.)
const llmReadyString = buildPrompt(prompt);
// Send to OpenAI, Anthropic, or your LLM provider
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: llmReadyString }]
});3. Lightweight Static Validation
Before sending prompts to production models, perform a sanity check to ensure no crucial piece of the framework was left empty or dangerously short.
import { validatePrompt } from '@lukefryer4/stco-prompt-builder';
const issues = validatePrompt(prompt);
if (issues.length > 0) {
console.warn("Prompt validation warnings:", issues);
}Note: This static validator only checks for empty or chronically short fields. For advanced AI-driven prompt grading and heuristic scoring, please use the Free Prompt Scorer Tool.
API Reference
buildPrompt(prompt: STCOPrompt, options?: BuildOptions): string
Takes your STCO object and formats it. Options include:
includeHeaders(boolean) - Adds### System,### Tasketc. Default:truewrapContent(boolean) - Wraps content in markdown text blocks. Default:false
Why Use This Package?
When you embed raw strings in your codebase, prompts become disorganised and difficult to maintain:
// BAD ❌
const prompt = `You are a developer. Fix this code. We use React. Give me code only.`;By enforcing the STCO framework via this package, you ensure consistent results across your entire engineering team.
// GOOD ✅
const llmReadyString = buildPrompt({
system: "You are a developer.",
task: "Fix this code.",
context: "We use React.",
output: "Give me code only."
});