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

assistantclj

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

Creates an assistant message. See internal.llm for details.
raw 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.
raw docstring

CARDINALITYclj

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

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

CARDINALITY_MANYclj

Cardinality: Vector of values.

Cardinality: Vector of values.
raw docstring

CARDINALITY_ONEclj

Cardinality: Single value.

Cardinality: Single value.
raw 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.
raw 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.
raw docstring

DESCRIPTIONclj

Field option: Human-readable field description.

Field option: Human-readable field description.
raw 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.
raw 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.
raw 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.
raw 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.
raw docstring

guardclj

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

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

GUARD_DEFAULT_INJECTION_PATTERNSclj

Default patterns for prompt injection detection.

Default patterns for prompt injection detection.
raw docstring

GUARD_DEFAULT_MODERATION_POLICIESclj

Default OpenAI moderation policies to check.

Default OpenAI moderation policies to check.
raw 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!.
raw 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.
raw 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.
raw 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}.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw docstring

KEY-NSclj

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

Spec option: Namespace prefix to add to keys during parsing.
raw 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.
raw docstring

make-configclj

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

Creates an LLM configuration map. See internal.config for details.
raw 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.
raw 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.
raw 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).
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw 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.
raw docstring

systemclj

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

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

TARGETclj

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

Field option: Reference target for :spec.type/ref fields.
raw 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).
raw docstring

TYPE_BOOLclj

Type: Boolean value.

Type: Boolean value.
raw docstring

TYPE_DATEclj

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

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

TYPE_DATETIMEclj

Type: ISO datetime.

Type: ISO datetime.
raw docstring

TYPE_DOUBLE_V_1clj

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

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

TYPE_DOUBLE_V_10clj

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

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

TYPE_DOUBLE_V_11clj

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

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

TYPE_DOUBLE_V_12clj

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

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

TYPE_DOUBLE_V_2clj

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

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

TYPE_DOUBLE_V_3clj

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

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

TYPE_DOUBLE_V_4clj

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

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

TYPE_DOUBLE_V_5clj

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

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

TYPE_DOUBLE_V_6clj

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

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

TYPE_DOUBLE_V_7clj

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

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

TYPE_DOUBLE_V_8clj

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

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

TYPE_DOUBLE_V_9clj

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

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

TYPE_FLOATclj

Type: Floating point value.

Type: Floating point value.
raw docstring

TYPE_INTclj

Type: Integer value.

Type: Integer value.
raw docstring

TYPE_INT_V_1clj

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

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

TYPE_INT_V_10clj

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

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

TYPE_INT_V_11clj

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

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

TYPE_INT_V_12clj

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

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

TYPE_INT_V_2clj

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

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

TYPE_INT_V_3clj

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

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

TYPE_INT_V_4clj

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

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

TYPE_INT_V_5clj

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

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

TYPE_INT_V_6clj

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

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

TYPE_INT_V_7clj

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

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

TYPE_INT_V_8clj

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

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

TYPE_INT_V_9clj

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

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

TYPE_KEYWORDclj

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

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

TYPE_REFclj

Type: Reference to another spec.

Type: Reference to another spec.
raw docstring

TYPE_STRINGclj

Type: String value.

Type: String value.
raw docstring

TYPE_STRING_V_1clj

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

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

TYPE_STRING_V_10clj

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

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

TYPE_STRING_V_11clj

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

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

TYPE_STRING_V_12clj

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

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

TYPE_STRING_V_2clj

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

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

TYPE_STRING_V_3clj

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

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

TYPE_STRING_V_4clj

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

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

TYPE_STRING_V_5clj

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

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

TYPE_STRING_V_6clj

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

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

TYPE_STRING_V_7clj

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

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

TYPE_STRING_V_8clj

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

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

TYPE_STRING_V_9clj

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

Type: Fixed-size string vector (9 elements).
raw 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).
raw 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.
raw 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.
raw docstring

VALUESclj

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

Field option: Enum values as map {value description}.
raw 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