2026-05-04 18:55:18 +00:00
# scriptorium
2026-05-05 11:16:33 -05:00
Scriptorium is a generic prompt execution engine.
2026-05-04 20:36:12 -05:00
2026-05-05 11:16:33 -05:00
It takes:
- a prompt definition
- a selected or default execution profile
- named input artifacts
- template variables
- optional runtime overrides
2026-05-04 21:08:40 -05:00
2026-05-05 11:16:33 -05:00
It returns:
- generated artifact
- validation result
- metadata
2026-05-04 21:08:40 -05:00
2026-05-05 11:16:33 -05:00
## Prompt vs Profile
2026-05-04 21:23:48 -05:00
2026-05-05 11:16:33 -05:00
Scriptorium separates **what ** to do (Prompt) from **how ** to do it (Profile).
2026-05-04 21:23:48 -05:00
2026-05-05 11:16:33 -05:00
### Prompt Definition
Defines the task logic and output contract.
- Task description and version.
- Message templates (system, user, etc.).
- Required and optional input artifacts.
- Output format and validation rules.
- Repair settings for structured output.
- Optional `default_profile` for convenience.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
### Execution Profile
Defines the runtime environment and model settings.
- LLM endpoint (URL).
- Model name.
- Generation parameters: `temperature` , `max_tokens` , `top_p` .
- Runtime settings: `timeout` , `reasoning_effort` .
- API key source via `api_key_env` .
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Callers can explicitly provide a `profile_id` to override the prompt's `default_profile` .
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
## Precedence
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
When resolving runtime settings, Scriptorium follows this precedence model (highest to lowest):
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
1. **Runtime Overrides ** : Provided via CLI flags or HTTP request `model` object.
2. **Execution Profile ** : Settings defined in the selected profile.
3. **Application Defaults ** : Built-in fallback values.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
### Profile Selection Logic
The engine determines which profile to use in this order:
1. Explicit `profile_id` (via `--profile` or HTTP request).
2. The `default_profile` named in the Prompt Definition.
3. Error: If neither is provided and no default exists.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
## API Key Policy
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
To ensure security, Scriptorium does not support raw API keys in configuration files, CLI arguments, or HTTP requests.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
- **`api_key_env` **: Profiles and overrides specify the name of an environment variable (e.g., `SCRIPTORIUM_API_KEY` ).
- **Runtime Resolution**: The value of the environment variable is read directly from the process environment at runtime.
- **Zero Leakage**: API key values are never included in metadata, logs, or response bodies.
2026-05-04 21:23:48 -05:00
2026-05-05 11:16:33 -05:00
## CLI Usage
2026-05-04 21:23:48 -05:00
2026-05-05 11:16:33 -05:00
### `scriptorium run`
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Runs a single prompt execution.
**Required Flags:**
- `--prompt-dir` : Directory containing prompt YAML files.
- `--profile-dir` : Directory containing profile YAML files.
- `--prompt` : The prompt ID to execute.
- `--input` : Input mapping `name=path` (repeatable).
**Optional Flags:**
- `--profile` : Override the prompt's default profile.
- `--var` : Template variable `name=value` (repeatable).
- `--out` : Write output to a file instead of stdout.
- `--llm-base-url` : Override endpoint.
- `--model` : Override model name.
- `--api-key-env` : Override API key environment variable name.
- `--temperature` : Override temperature.
- `--max-tokens` : Override max tokens.
- `--top-p` : Override top_p.
- `--timeout` : Override request timeout (e.g., `30s` , `1m` ).
**Examples:**
Using the prompt's `default_profile` :
```bash
export SCRIPTORIUM_API_KEY="sk-..."
scriptorium run \
--prompt-dir ./prompts \
--profile-dir ./profiles \
--prompt generic.markdown_summary \
--input transcript=./examples/fixtures/transcript.md
```
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Overriding the profile:
```bash
scriptorium run \
--prompt-dir ./prompts \
--profile-dir ./profiles \
--prompt generic.markdown_summary \
--profile local-quality \
--input transcript=./examples/fixtures/transcript.md
```
2026-05-04 21:08:40 -05:00
2026-05-05 11:16:33 -05:00
Overriding model and runtime values:
2026-05-04 21:08:40 -05:00
```bash
2026-05-05 11:16:33 -05:00
scriptorium run \
--prompt-dir ./prompts \
--profile-dir ./profiles \
--prompt generic.markdown_summary \
--model gpt-4o \
--temperature 0.7 \
--input transcript=./examples/fixtures/transcript.md
```
2026-05-04 21:23:48 -05:00
2026-05-05 11:16:33 -05:00
Using a local OpenAI-compatible vLLM endpoint:
```bash
scriptorium run \
2026-05-05 10:58:22 -05:00
--prompt-dir ./prompts \
2026-05-04 21:23:48 -05:00
--profile-dir ./profiles \
2026-05-05 10:58:22 -05:00
--prompt generic.markdown_summary \
2026-05-04 21:23:48 -05:00
--llm-base-url http://localhost:8000/v1 \
2026-05-05 11:16:33 -05:00
--model meta-llama-3-8b \
--input transcript=./examples/fixtures/transcript.md
2026-05-04 21:23:48 -05:00
```
2026-05-05 08:45:10 -05:00
### `scriptorium serve`
2026-05-05 11:16:33 -05:00
Starts the HTTP API.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
**Required Flags:**
- `--prompt-dir` : Directory containing prompt YAML files.
- `--profile-dir` : Directory containing profile YAML files.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
**Optional Flags:**
- `--addr` : Listen address (default `:8080` ).
- `--schema-dir` : Base directory for validation schemas.
- `--model` : Default model override.
- `--timeout` : Default request timeout.
2026-05-05 08:45:10 -05:00
## HTTP API
2026-05-05 11:16:33 -05:00
### `POST /v1/runs`
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Executes a prompt. No built-in authentication is provided; deploy behind a trusted gateway.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
**Request Body:**
2026-05-05 08:45:10 -05:00
```json
{
2026-05-05 10:09:31 -05:00
"prompt_id": "generic.structured_events",
2026-05-05 11:16:33 -05:00
"profile_id": "local-quality",
2026-05-05 08:45:10 -05:00
"inputs": {
2026-05-05 11:16:33 -05:00
"transcript": {"type": "file", "uri": "./examples/fixtures/transcript.md"}
2026-05-05 08:45:10 -05:00
},
"vars": {
"session_date": "2026-05-04"
},
"model": {
"endpoint": "http://localhost:8000/v1",
"model": "gpt-4o-mini",
2026-05-05 11:16:33 -05:00
"temperature": 0.0
2026-05-05 08:45:10 -05:00
}
}
```
2026-05-05 11:16:33 -05:00
**Response:**
Returns a `200 OK` with the generated artifact, validation results, and metadata including the `prompt_id` and the `selected_profile_id` .
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
**Validation Failures:**
If the model output fails validation (e.g., invalid JSON), the API returns `200 OK` with `validation.status = "failed"` . The original `raw_model_output` is preserved in the response to allow debugging.
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
## Prompt Definition Authoring
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Prompts are defined in YAML.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
### Canonical Shape
2026-05-05 08:45:10 -05:00
```yaml
id: generic.structured_events
version: "1.0.0"
2026-05-05 11:16:33 -05:00
description: "Extracts structured events from a transcript"
default_profile: local-quality
2026-05-05 10:09:31 -05:00
inputs:
- name: transcript
required: true
2026-05-05 11:16:33 -05:00
description: "The raw session transcript"
- name: glossary
required: false
2026-05-05 08:45:10 -05:00
templates:
- role: system
2026-05-05 11:16:33 -05:00
content: "You are a helpful assistant."
2026-05-05 08:45:10 -05:00
- role: user
2026-05-05 11:16:33 -05:00
content_file: messages/extract_events.tmpl
2026-05-05 08:45:10 -05:00
output_format: json
validation:
validation_mode: json_schema
schema_path: structured_events.schema.json
2026-05-05 11:16:33 -05:00
repair_attempts: 2
2026-05-05 08:45:10 -05:00
```
2026-05-05 11:16:33 -05:00
**Key Features:**
- **Inline vs File**: Use `content` for short prompts or `content_file` for larger templates.
- **Inputs**: Mark inputs as `required` to ensure the runner fails early if they are missing.
- **Validation**: Support `none` , `basic` , `json` , and `json_schema` .
- **Repair**: `repair_attempts` enables bounded retries to fix structured output.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
## Execution Profile Authoring
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
Profiles are defined in YAML.
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
### Canonical Shape
```yaml
id: local-quality
endpoint: http://localhost:8000/v1
model: gpt-4o
temperature: 0.0
max_tokens: 4096
top_p: 1.0
timeout_seconds: 300
reasoning_effort: high
api_key_env: SCRIPTORIUM_API_KEY
```
**Constraints:**
- **No Raw Keys**: Do not include actual API keys. Only specify the environment variable name in `api_key_env` .
- **Local Profiles**: For local endpoints that don't require auth, `api_key_env` can be omitted.
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
## Examples
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
- **Prompt Definitions**: `prompts/`
- **Execution Profiles**: `profiles/`
- **Schemas**: `schemas/`
- **Fixtures**: `examples/fixtures/`
- **Local Experimentation**: `local-test/`
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
## Build and Test
2026-05-05 08:45:10 -05:00
2026-05-05 11:16:33 -05:00
```bash
go build -o scriptorium ./cmd/scriptorium
go test ./...
```