LLM interaction utilities for structured and unstructured outputs.
SVAR = Structured Validated Automated Reasoning
Provides main functions:
ask! - Structured output using the spec DSLabstract! - Text summarization using Chain of Density promptingeval! - LLM self-evaluation for reliability and accuracy assessmentrefine! - Iterative refinement using decomposition and verificationmodels! - Fetch available models from the LLM APIsample! - Generate test data samples matching a specGuardrails:
static-guard - Pattern-based prompt injection detectionmoderation-guard - LLM-based content moderationguard - Run one or more guards on inputHumanization:
humanize-string - Strip AI-style phrases from texthumanize-data - Humanize string values in data structureshumanizer - Create a reusable humanizer functionPageIndex:
index! - Index a document file (PDF, MD, TXT) and save structured dataload-index - Load an indexed document from a pageindex directoryRe-exports spec DSL (field, spec, str->data, str->data-with-spec,
data->str, validate-data, spec->prompt, build-ref-registry),
RLM (create-env, register-env-fn!, register-env-def!, ingest-to-env!, dispose-env!,
query-env!, pprint-trace, print-trace, generate-qa-env!),
PageIndex (index!, load-index), and
make-config so users can require only this namespace.
Configuration: Config MUST be passed explicitly to all LLM functions via the :config parameter. No global state. No dependency injection.
Example: (def config (make-config {:api-key "sk-..." :base-url "https://api.openai.com/v1"})) (ask! {:config config :spec my-spec :messages [(system "Help the user.") (user "What is 2+2?")] :model "gpt-4o"})
References:
LLM interaction utilities for structured and unstructured outputs.
SVAR = Structured Validated Automated Reasoning
Provides main functions:
- `ask!` - Structured output using the spec DSL
- `abstract!` - Text summarization using Chain of Density prompting
- `eval!` - LLM self-evaluation for reliability and accuracy assessment
- `refine!` - Iterative refinement using decomposition and verification
- `models!` - Fetch available models from the LLM API
- `sample!` - Generate test data samples matching a spec
Guardrails:
- `static-guard` - Pattern-based prompt injection detection
- `moderation-guard` - LLM-based content moderation
- `guard` - Run one or more guards on input
Humanization:
- `humanize-string` - Strip AI-style phrases from text
- `humanize-data` - Humanize string values in data structures
- `humanizer` - Create a reusable humanizer function
PageIndex:
- `index!` - Index a document file (PDF, MD, TXT) and save structured data
- `load-index` - Load an indexed document from a pageindex directory
Re-exports spec DSL (`field`, `spec`, `str->data`, `str->data-with-spec`,
`data->str`, `validate-data`, `spec->prompt`, `build-ref-registry`),
RLM (`create-env`, `register-env-fn!`, `register-env-def!`, `ingest-to-env!`, `dispose-env!`,
`query-env!`, `pprint-trace`, `print-trace`, `generate-qa-env!`),
PageIndex (`index!`, `load-index`), and
`make-config` so users can require only this namespace.
Configuration:
Config MUST be passed explicitly to all LLM functions via the :config parameter.
No global state. No dependency injection.
Example:
(def config (make-config {:api-key "sk-..." :base-url "https://api.openai.com/v1"}))
(ask! {:config config
:spec my-spec
:messages [(system "Help the user.")
(user "What is 2+2?")]
:model "gpt-4o"})
References:
- Chain of Density: https://arxiv.org/abs/2309.04269
- LLM Self-Evaluation: https://learnprompting.org/docs/reliability/lm_self_eval
- DuTy: https://learnprompting.org/docs/advanced/decomposition/duty-distinct-chain-of-thought
- CoVe: https://learnprompting.org/docs/advanced/self_criticism/chain_of_verificationCreates a dense, entity-rich summary using Chain of Density prompting. See internal.llm for details.
Creates a dense, entity-rich summary using Chain of Density prompting. See internal.llm for details.
Asks the LLM and returns structured Clojure data with token usage and cost. See internal.llm for details.
Asks the LLM and returns structured Clojure data with token usage and cost. See internal.llm for details.
Creates an assistant message. See internal.llm for details.
Creates an assistant message. See internal.llm for details.
Builds a registry of referenced specs. See spec namespace for details.
Builds a registry of referenced specs. See spec namespace for details.
Field option: Field cardinality (:spec.cardinality/one or :spec.cardinality/many).
Field option: Field cardinality (:spec.cardinality/one or :spec.cardinality/many).
Creates an RLM environment for processing large contexts via iterative code execution. See internal.rlm for details.
Creates an RLM environment for processing large contexts via iterative code execution. See internal.rlm for details.
Serializes Clojure data to LLM-compatible string. See spec namespace for details.
Serializes Clojure data to LLM-compatible string. See spec namespace for details.
Field option: Human-readable field description.
Field option: Human-readable field description.
Disposes an RLM environment and cleans up resources. See internal.rlm for details.
Disposes an RLM environment and cleans up resources. See internal.rlm for details.
Evaluates an LLM output using LLM self-evaluation. See internal.llm for details.
Evaluates an LLM output using LLM self-evaluation. See internal.llm for details.
Creates a field definition for a spec. See spec namespace for details.
Creates a field definition for a spec. See spec namespace for details.
Generates question-answer pairs from ingested documents using a multi-stage pipeline. See internal.rlm for details.
Generates question-answer pairs from ingested documents using a multi-stage pipeline. See internal.rlm for details.
Runs guard(s) on input. See internal.guard for details.
Runs guard(s) on input. See internal.guard for details.
Default patterns for prompt injection detection.
Default patterns for prompt injection detection.
Default OpenAI moderation policies to check.
Default OpenAI moderation policies to check.
Field option: When true, marks field for humanization via :humanizer in ask!.
Field option: When true, marks field for humanization via :humanizer in ask!.
Recursively humanizes all strings in a data structure. See internal.humanize for details.
Recursively humanizes all strings in a data structure. See internal.humanize for details.
Removes AI-style phrases from text to make it sound more natural. See internal.humanize for details.
Removes AI-style phrases from text to make it sound more natural. See internal.humanize for details.
Aggressive humanization patterns: hedging, overused verbs/adjectives/nouns, cliches. May match valid English -- opt-in only via {:aggressive? true}.
Aggressive humanization patterns: hedging, overused verbs/adjectives/nouns, cliches.
May match valid English -- opt-in only via {:aggressive? true}.Default patterns for AI phrase humanization (safe + aggressive combined). Preserved for backward compatibility.
Default patterns for AI phrase humanization (safe + aggressive combined). Preserved for backward compatibility.
Safe humanization patterns: AI identity, refusal, knowledge, punctuation. These are unambiguously AI artifacts, safe for arbitrary text.
Safe humanization patterns: AI identity, refusal, knowledge, punctuation. These are unambiguously AI artifacts, safe for arbitrary text.
Creates a humanization function with optional custom patterns. See internal.humanize for details.
Creates a humanization function with optional custom patterns. See internal.humanize for details.
Creates an image attachment for use with user messages.
See internal.llm for details.
Creates an image attachment for use with `user` messages. See internal.llm for details.
Index a document file (PDF, MD, TXT) and save structured data as EDN + PNG files.
Creates a .pageindex directory alongside the original file containing: document.edn — structured document data images/ — extracted images as PNG files
Opts: :config - LLM config override :pages - Page selector (1-indexed). Limits which pages are indexed. Supports: integer, [from to] range, or [[1 3] 5 [7 10]] mixed. nil = all pages (default).
Vision extraction: :vision-model - Model for vision page extraction :parallel - Max concurrent vision page extractions (default: 3)
Quality refinement: :refine? - Enable post-extraction quality refinement (default: false) :refine-model - Model for eval/refine steps (default: "gpt-4o") :parallel-refine - Max concurrent eval/refine operations (default: 2)
Example: (svar/index! "docs/manual.pdf") (svar/index! "docs/manual.pdf" {:pages [1 5]}) (svar/index! "docs/manual.pdf" {:pages [[1 3] 5 [7 10]]}) (svar/index! "docs/manual.pdf" {:vision-model "gpt-4o" :parallel 5 :refine? true :refine-model "gpt-4o-mini" :parallel-refine 3})
See internal.rlm.internal.pageindex.core for full options.
Index a document file (PDF, MD, TXT) and save structured data as EDN + PNG files.
Creates a .pageindex directory alongside the original file containing:
document.edn — structured document data
images/ — extracted images as PNG files
Opts:
:config - LLM config override
:pages - Page selector (1-indexed). Limits which pages are indexed.
Supports: integer, [from to] range, or [[1 3] 5 [7 10]] mixed.
nil = all pages (default).
Vision extraction:
:vision-model - Model for vision page extraction
:parallel - Max concurrent vision page extractions (default: 3)
Quality refinement:
:refine? - Enable post-extraction quality refinement (default: false)
:refine-model - Model for eval/refine steps (default: "gpt-4o")
:parallel-refine - Max concurrent eval/refine operations (default: 2)
Example:
(svar/index! "docs/manual.pdf")
(svar/index! "docs/manual.pdf" {:pages [1 5]})
(svar/index! "docs/manual.pdf" {:pages [[1 3] 5 [7 10]]})
(svar/index! "docs/manual.pdf" {:vision-model "gpt-4o"
:parallel 5
:refine? true
:refine-model "gpt-4o-mini"
:parallel-refine 3})
See internal.rlm.internal.pageindex.core for full options.Ingests documents into an RLM environment for querying. See internal.rlm for details.
Ingests documents into an RLM environment for querying. See internal.rlm for details.
Spec option: Namespace prefix to add to keys during parsing.
Spec option: Namespace prefix to add to keys during parsing.
Load an indexed document from a .pageindex directory.
Reads the EDN + PNG files produced by index! and returns the document map.
Also supports loading legacy formats for backward compatibility.
Example: (svar/load-index "docs/manual.pageindex")
See internal.rlm.internal.pageindex.core for details.
Load an indexed document from a .pageindex directory. Reads the EDN + PNG files produced by `index!` and returns the document map. Also supports loading legacy formats for backward compatibility. Example: (svar/load-index "docs/manual.pageindex") See internal.rlm.internal.pageindex.core for details.
Creates an LLM configuration map. See internal.config for details.
Creates an LLM configuration map. See internal.config for details.
Fetches available models from the LLM API. See internal.llm for details.
Fetches available models from the LLM API. See internal.llm for details.
Creates a guard function that uses LLM to check content against policies. See internal.guard for details.
Creates a guard function that uses LLM to check content against policies. See internal.guard for details.
Field option: Field name as Datomic-style keyword (e.g., :user/name).
Field option: Field name as Datomic-style keyword (e.g., :user/name).
Pretty-prints an RLM trace to a string. See internal.rlm for details.
Pretty-prints an RLM trace to a string. See internal.rlm for details.
Pretty-prints an RLM trace to stdout. See internal.rlm for details.
Pretty-prints an RLM trace to stdout. See internal.rlm for details.
Runs a query against an RLM environment using iterative code execution. See internal.rlm for details.
Runs a query against an RLM environment using iterative code execution. See internal.rlm for details.
Iteratively refines LLM output using decomposition and verification. See internal.llm for details.
Iteratively refines LLM output using decomposition and verification. See internal.llm for details.
Registers a constant in the RLM's SCI sandbox. See internal.rlm for details.
Registers a constant in the RLM's SCI sandbox. See internal.rlm for details.
Registers a custom function in the RLM's SCI sandbox. See internal.rlm for details.
Registers a custom function in the RLM's SCI sandbox. See internal.rlm for details.
Field option: Whether field is required (default: true). Set to false for optional.
Field option: Whether field is required (default: true). Set to false for optional.
Generates test data samples matching a spec with self-correction. See internal.llm for details.
Generates test data samples matching a spec with self-correction. See internal.llm for details.
Saves generate-qa-env! results to EDN and/or Markdown files. See internal.rlm for details.
Saves generate-qa-env! results to EDN and/or Markdown files. See internal.rlm for details.
Creates a spec definition from field definitions. See spec namespace for details.
Creates a spec definition from field definitions. See spec namespace for details.
Generates LLM prompt from a spec. See spec namespace for details.
Generates LLM prompt from a spec. See spec namespace for details.
Creates a guard function that checks for prompt injection patterns. See internal.guard for details.
Creates a guard function that checks for prompt injection patterns. See internal.guard for details.
Parses LLM response string to Clojure data. See spec namespace for details.
Parses LLM response string to Clojure data. See spec namespace for details.
Parses LLM response with spec validation. See spec namespace for details.
Parses LLM response with spec validation. See spec namespace for details.
Creates a system message. See internal.llm for details.
Creates a system message. See internal.llm for details.
Field option: Reference target for :spec.type/ref fields.
Field option: Reference target for :spec.type/ref fields.
Field option: Field type (e.g., :spec.type/string, :spec.type/int).
Field option: Field type (e.g., :spec.type/string, :spec.type/int).
Type: Fixed-size double vector (1 element).
Type: Fixed-size double vector (1 element).
Type: Fixed-size double vector (10 elements).
Type: Fixed-size double vector (10 elements).
Type: Fixed-size double vector (11 elements).
Type: Fixed-size double vector (11 elements).
Type: Fixed-size double vector (12 elements).
Type: Fixed-size double vector (12 elements).
Type: Fixed-size double vector (2 elements).
Type: Fixed-size double vector (2 elements).
Type: Fixed-size double vector (3 elements).
Type: Fixed-size double vector (3 elements).
Type: Fixed-size double vector (4 elements).
Type: Fixed-size double vector (4 elements).
Type: Fixed-size double vector (5 elements).
Type: Fixed-size double vector (5 elements).
Type: Fixed-size double vector (6 elements).
Type: Fixed-size double vector (6 elements).
Type: Fixed-size double vector (7 elements).
Type: Fixed-size double vector (7 elements).
Type: Fixed-size double vector (8 elements).
Type: Fixed-size double vector (8 elements).
Type: Fixed-size double vector (9 elements).
Type: Fixed-size double vector (9 elements).
Type: Fixed-size integer vector (1 element).
Type: Fixed-size integer vector (1 element).
Type: Fixed-size integer vector (10 elements).
Type: Fixed-size integer vector (10 elements).
Type: Fixed-size integer vector (11 elements).
Type: Fixed-size integer vector (11 elements).
Type: Fixed-size integer vector (12 elements).
Type: Fixed-size integer vector (12 elements).
Type: Fixed-size integer vector (2 elements).
Type: Fixed-size integer vector (2 elements).
Type: Fixed-size integer vector (3 elements).
Type: Fixed-size integer vector (3 elements).
Type: Fixed-size integer vector (4 elements).
Type: Fixed-size integer vector (4 elements).
Type: Fixed-size integer vector (5 elements).
Type: Fixed-size integer vector (5 elements).
Type: Fixed-size integer vector (6 elements).
Type: Fixed-size integer vector (6 elements).
Type: Fixed-size integer vector (7 elements).
Type: Fixed-size integer vector (7 elements).
Type: Fixed-size integer vector (8 elements).
Type: Fixed-size integer vector (8 elements).
Type: Fixed-size integer vector (9 elements).
Type: Fixed-size integer vector (9 elements).
Type: Clojure keyword (rendered as string, keywordized on parse).
Type: Clojure keyword (rendered as string, keywordized on parse).
Type: Fixed-size string vector (1 element).
Type: Fixed-size string vector (1 element).
Type: Fixed-size string vector (10 elements).
Type: Fixed-size string vector (10 elements).
Type: Fixed-size string vector (11 elements).
Type: Fixed-size string vector (11 elements).
Type: Fixed-size string vector (12 elements).
Type: Fixed-size string vector (12 elements).
Type: Fixed-size string vector (2 elements).
Type: Fixed-size string vector (2 elements).
Type: Fixed-size string vector (3 elements).
Type: Fixed-size string vector (3 elements).
Type: Fixed-size string vector (4 elements).
Type: Fixed-size string vector (4 elements).
Type: Fixed-size string vector (5 elements).
Type: Fixed-size string vector (5 elements).
Type: Fixed-size string vector (6 elements).
Type: Fixed-size string vector (6 elements).
Type: Fixed-size string vector (7 elements).
Type: Fixed-size string vector (7 elements).
Type: Fixed-size string vector (8 elements).
Type: Fixed-size string vector (8 elements).
Type: Fixed-size string vector (9 elements).
Type: Fixed-size string vector (9 elements).
Field option: Set of allowed nil types (used internally for optional fields).
Field option: Set of allowed nil types (used internally for optional fields).
Creates a user message, optionally with images. See internal.llm for details.
Creates a user message, optionally with images. See internal.llm for details.
Validates parsed data against a spec. See spec namespace for details.
Validates parsed data against a spec. See spec namespace for details.
Field option: Enum values as map {value description}.
Field option: Enum values as map {value description}.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |