Liking cljdoc? Tell your friends :D

com.blockether.svar.core

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:

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_verification
raw docstring

abstract!clj

Creates 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.
sourceraw docstring

ask!clj

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.
sourceraw docstring

assistantclj

Creates an assistant message. See internal.llm for details.

Creates an assistant message. See internal.llm for details.
sourceraw docstring

build-ref-registryclj

Builds a registry of referenced specs. See spec namespace for details.

Builds a registry of referenced specs. See spec namespace for details.
sourceraw docstring

CARDINALITYclj

Field option: Field cardinality (:spec.cardinality/one or :spec.cardinality/many).

Field option: Field cardinality (:spec.cardinality/one or :spec.cardinality/many).
sourceraw docstring

CARDINALITY_MANYclj

Cardinality: Vector of values.

Cardinality: Vector of values.
sourceraw docstring

CARDINALITY_ONEclj

Cardinality: Single value.

Cardinality: Single value.
sourceraw docstring

create-envclj

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.
sourceraw docstring

data->strclj

Serializes Clojure data to LLM-compatible string. See spec namespace for details.

Serializes Clojure data to LLM-compatible string. See spec namespace for details.
sourceraw docstring

DESCRIPTIONclj

Field option: Human-readable field description.

Field option: Human-readable field description.
sourceraw docstring

dispose-env!clj

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.
sourceraw docstring

eval!clj

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.
sourceraw docstring

fieldclj

Creates a field definition for a spec. See spec namespace for details.

Creates a field definition for a spec. See spec namespace for details.
sourceraw docstring

generate-qa-env!clj

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.
sourceraw docstring

guardclj

Runs guard(s) on input. See internal.guard for details.

Runs guard(s) on input. See internal.guard for details.
sourceraw docstring

GUARD_DEFAULT_INJECTION_PATTERNSclj

Default patterns for prompt injection detection.

Default patterns for prompt injection detection.
sourceraw docstring

GUARD_DEFAULT_MODERATION_POLICIESclj

Default OpenAI moderation policies to check.

Default OpenAI moderation policies to check.
sourceraw docstring

HUMANIZEclj

Field option: When true, marks field for humanization via :humanizer in ask!.

Field option: When true, marks field for humanization via :humanizer in ask!.
sourceraw docstring

humanize-dataclj

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.
sourceraw docstring

humanize-stringclj

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.
sourceraw docstring

HUMANIZE_AGGRESSIVE_PATTERNSclj

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}.
sourceraw docstring

HUMANIZE_DEFAULT_PATTERNSclj

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.
sourceraw docstring

HUMANIZE_SAFE_PATTERNSclj

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.
sourceraw docstring

humanizerclj

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.
sourceraw docstring

imageclj

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.
sourceraw docstring

index!clj

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.
sourceraw docstring

ingest-to-env!clj

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.
sourceraw docstring

KEY-NSclj

Spec option: Namespace prefix to add to keys during parsing.

Spec option: Namespace prefix to add to keys during parsing.
sourceraw docstring

load-indexclj

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.
sourceraw docstring

make-configclj

Creates an LLM configuration map. See internal.config for details.

Creates an LLM configuration map. See internal.config for details.
sourceraw docstring

models!clj

Fetches available models from the LLM API. See internal.llm for details.

Fetches available models from the LLM API.
See internal.llm for details.
sourceraw docstring

moderation-guardclj

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.
sourceraw docstring

NAMEclj

Field option: Field name as Datomic-style keyword (e.g., :user/name).

Field option: Field name as Datomic-style keyword (e.g., :user/name).
sourceraw docstring

pprint-traceclj

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.
sourceraw docstring

Pretty-prints an RLM trace to stdout. See internal.rlm for details.

Pretty-prints an RLM trace to stdout.
See internal.rlm for details.
sourceraw docstring

query-env!clj

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.
sourceraw docstring

refine!clj

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.
sourceraw docstring

register-env-def!clj

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.
sourceraw docstring

register-env-fn!clj

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.
sourceraw docstring

REQUIREDclj

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.
sourceraw docstring

sample!clj

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.
sourceraw docstring

save-qa!clj

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.
sourceraw docstring

specclj

Creates a spec definition from field definitions. See spec namespace for details.

Creates a spec definition from field definitions. See spec namespace for details.
sourceraw docstring

spec->promptclj

Generates LLM prompt from a spec. See spec namespace for details.

Generates LLM prompt from a spec. See spec namespace for details.
sourceraw docstring

static-guardclj

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.
sourceraw docstring

str->dataclj

Parses LLM response string to Clojure data. See spec namespace for details.

Parses LLM response string to Clojure data. See spec namespace for details.
sourceraw docstring

str->data-with-specclj

Parses LLM response with spec validation. See spec namespace for details.

Parses LLM response with spec validation. See spec namespace for details.
sourceraw docstring

systemclj

Creates a system message. See internal.llm for details.

Creates a system message. See internal.llm for details.
sourceraw docstring

TARGETclj

Field option: Reference target for :spec.type/ref fields.

Field option: Reference target for :spec.type/ref fields.
sourceraw docstring

TYPEclj

Field option: Field type (e.g., :spec.type/string, :spec.type/int).

Field option: Field type (e.g., :spec.type/string, :spec.type/int).
sourceraw docstring

TYPE_BOOLclj

Type: Boolean value.

Type: Boolean value.
sourceraw docstring

TYPE_DATEclj

Type: ISO date (YYYY-MM-DD).

Type: ISO date (YYYY-MM-DD).
sourceraw docstring

TYPE_DATETIMEclj

Type: ISO datetime.

Type: ISO datetime.
sourceraw docstring

TYPE_DOUBLE_V_1clj

Type: Fixed-size double vector (1 element).

Type: Fixed-size double vector (1 element).
sourceraw docstring

TYPE_DOUBLE_V_10clj

Type: Fixed-size double vector (10 elements).

Type: Fixed-size double vector (10 elements).
sourceraw docstring

TYPE_DOUBLE_V_11clj

Type: Fixed-size double vector (11 elements).

Type: Fixed-size double vector (11 elements).
sourceraw docstring

TYPE_DOUBLE_V_12clj

Type: Fixed-size double vector (12 elements).

Type: Fixed-size double vector (12 elements).
sourceraw docstring

TYPE_DOUBLE_V_2clj

Type: Fixed-size double vector (2 elements).

Type: Fixed-size double vector (2 elements).
sourceraw docstring

TYPE_DOUBLE_V_3clj

Type: Fixed-size double vector (3 elements).

Type: Fixed-size double vector (3 elements).
sourceraw docstring

TYPE_DOUBLE_V_4clj

Type: Fixed-size double vector (4 elements).

Type: Fixed-size double vector (4 elements).
sourceraw docstring

TYPE_DOUBLE_V_5clj

Type: Fixed-size double vector (5 elements).

Type: Fixed-size double vector (5 elements).
sourceraw docstring

TYPE_DOUBLE_V_6clj

Type: Fixed-size double vector (6 elements).

Type: Fixed-size double vector (6 elements).
sourceraw docstring

TYPE_DOUBLE_V_7clj

Type: Fixed-size double vector (7 elements).

Type: Fixed-size double vector (7 elements).
sourceraw docstring

TYPE_DOUBLE_V_8clj

Type: Fixed-size double vector (8 elements).

Type: Fixed-size double vector (8 elements).
sourceraw docstring

TYPE_DOUBLE_V_9clj

Type: Fixed-size double vector (9 elements).

Type: Fixed-size double vector (9 elements).
sourceraw docstring

TYPE_FLOATclj

Type: Floating point value.

Type: Floating point value.
sourceraw docstring

TYPE_INTclj

Type: Integer value.

Type: Integer value.
sourceraw docstring

TYPE_INT_V_1clj

Type: Fixed-size integer vector (1 element).

Type: Fixed-size integer vector (1 element).
sourceraw docstring

TYPE_INT_V_10clj

Type: Fixed-size integer vector (10 elements).

Type: Fixed-size integer vector (10 elements).
sourceraw docstring

TYPE_INT_V_11clj

Type: Fixed-size integer vector (11 elements).

Type: Fixed-size integer vector (11 elements).
sourceraw docstring

TYPE_INT_V_12clj

Type: Fixed-size integer vector (12 elements).

Type: Fixed-size integer vector (12 elements).
sourceraw docstring

TYPE_INT_V_2clj

Type: Fixed-size integer vector (2 elements).

Type: Fixed-size integer vector (2 elements).
sourceraw docstring

TYPE_INT_V_3clj

Type: Fixed-size integer vector (3 elements).

Type: Fixed-size integer vector (3 elements).
sourceraw docstring

TYPE_INT_V_4clj

Type: Fixed-size integer vector (4 elements).

Type: Fixed-size integer vector (4 elements).
sourceraw docstring

TYPE_INT_V_5clj

Type: Fixed-size integer vector (5 elements).

Type: Fixed-size integer vector (5 elements).
sourceraw docstring

TYPE_INT_V_6clj

Type: Fixed-size integer vector (6 elements).

Type: Fixed-size integer vector (6 elements).
sourceraw docstring

TYPE_INT_V_7clj

Type: Fixed-size integer vector (7 elements).

Type: Fixed-size integer vector (7 elements).
sourceraw docstring

TYPE_INT_V_8clj

Type: Fixed-size integer vector (8 elements).

Type: Fixed-size integer vector (8 elements).
sourceraw docstring

TYPE_INT_V_9clj

Type: Fixed-size integer vector (9 elements).

Type: Fixed-size integer vector (9 elements).
sourceraw docstring

TYPE_KEYWORDclj

Type: Clojure keyword (rendered as string, keywordized on parse).

Type: Clojure keyword (rendered as string, keywordized on parse).
sourceraw docstring

TYPE_REFclj

Type: Reference to another spec.

Type: Reference to another spec.
sourceraw docstring

TYPE_STRINGclj

Type: String value.

Type: String value.
sourceraw docstring

TYPE_STRING_V_1clj

Type: Fixed-size string vector (1 element).

Type: Fixed-size string vector (1 element).
sourceraw docstring

TYPE_STRING_V_10clj

Type: Fixed-size string vector (10 elements).

Type: Fixed-size string vector (10 elements).
sourceraw docstring

TYPE_STRING_V_11clj

Type: Fixed-size string vector (11 elements).

Type: Fixed-size string vector (11 elements).
sourceraw docstring

TYPE_STRING_V_12clj

Type: Fixed-size string vector (12 elements).

Type: Fixed-size string vector (12 elements).
sourceraw docstring

TYPE_STRING_V_2clj

Type: Fixed-size string vector (2 elements).

Type: Fixed-size string vector (2 elements).
sourceraw docstring

TYPE_STRING_V_3clj

Type: Fixed-size string vector (3 elements).

Type: Fixed-size string vector (3 elements).
sourceraw docstring

TYPE_STRING_V_4clj

Type: Fixed-size string vector (4 elements).

Type: Fixed-size string vector (4 elements).
sourceraw docstring

TYPE_STRING_V_5clj

Type: Fixed-size string vector (5 elements).

Type: Fixed-size string vector (5 elements).
sourceraw docstring

TYPE_STRING_V_6clj

Type: Fixed-size string vector (6 elements).

Type: Fixed-size string vector (6 elements).
sourceraw docstring

TYPE_STRING_V_7clj

Type: Fixed-size string vector (7 elements).

Type: Fixed-size string vector (7 elements).
sourceraw docstring

TYPE_STRING_V_8clj

Type: Fixed-size string vector (8 elements).

Type: Fixed-size string vector (8 elements).
sourceraw docstring

TYPE_STRING_V_9clj

Type: Fixed-size string vector (9 elements).

Type: Fixed-size string vector (9 elements).
sourceraw docstring

UNIONclj

Field option: Set of allowed nil types (used internally for optional fields).

Field option: Set of allowed nil types (used internally for optional fields).
sourceraw docstring

userclj

Creates a user message, optionally with images. See internal.llm for details.

Creates a user message, optionally with images. See internal.llm for details.
sourceraw docstring

validate-dataclj

Validates parsed data against a spec. See spec namespace for details.

Validates parsed data against a spec. See spec namespace for details.
sourceraw docstring

VALUESclj

Field option: Enum values as map {value description}.

Field option: Enum values as map {value description}.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close