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

Re-exports spec DSL (field, spec, str->data, str->data-with-spec, data->str, validate-data, spec->prompt, build-ref-registry), and make-router so users can require only this namespace.

Configuration: LLM calls route automatically via the default router.

Example: (ask! {: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

  Re-exports spec DSL (`field`, `spec`, `str->data`, `str->data-with-spec`,
  `data->str`, `validate-data`, `spec->prompt`, `build-ref-registry`),
  and `make-router` so users can require only this namespace.

Configuration:
LLM calls route automatically via the default router.

 Example:
  (ask! {: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.

Creates a dense, entity-rich summary using Chain of Density prompting.
sourceraw docstring

ask!clj

Asks the LLM and returns structured Clojure data with token usage and cost.

Asks the LLM and returns structured Clojure data with token usage and cost.
sourceraw docstring

assistantclj

Creates an assistant message.

Creates an assistant message.
sourceraw docstring

build-ref-registryclj

Builds a registry of referenced specs.

Builds a registry of referenced specs.
sourceraw docstring

CARDINALITYclj

Field option: Field cardinality.

Field option: Field cardinality.
sourceraw docstring

CARDINALITY_MANYclj

Cardinality: Vector of values.

Cardinality: Vector of values.
sourceraw docstring

CARDINALITY_ONEclj

Cardinality: Single value.

Cardinality: Single value.
sourceraw docstring

data->strclj

Serializes Clojure data to LLM-compatible string.

Serializes Clojure data to LLM-compatible string.
sourceraw docstring

DESCRIPTIONclj

Field option: Human-readable field description.

Field option: Human-readable field description.
sourceraw docstring

eval!clj

Evaluates an LLM output using LLM self-evaluation.

Evaluates an LLM output using LLM self-evaluation.
sourceraw docstring

fieldclj

Creates a field definition for a spec.

Creates a field definition for a spec.
sourceraw docstring

guardclj

Runs guard(s) on input.

Runs guard(s) on input.
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.

Field option: When true, marks field for humanization.
sourceraw docstring

humanize-dataclj

Recursively humanizes all strings in a data structure.

Recursively humanizes all strings in a data structure.
sourceraw docstring

humanize-stringclj

Removes AI-style phrases from text.

Removes AI-style phrases from text.
sourceraw docstring

HUMANIZE_AGGRESSIVE_PATTERNSclj

Aggressive humanization patterns: hedging, overused verbs/adjectives/nouns.

Aggressive humanization patterns: hedging, overused verbs/adjectives/nouns.
sourceraw docstring

HUMANIZE_SAFE_PATTERNSclj

Safe humanization patterns: AI identity, refusal, knowledge, punctuation.

Safe humanization patterns: AI identity, refusal, knowledge, punctuation.
sourceraw docstring

humanizerclj

Creates a humanization function with optional custom patterns.

Creates a humanization function with optional custom patterns.
sourceraw docstring

imageclj

Creates an image attachment for use with user messages.

Creates an image attachment for use with `user` messages.
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

make-routerclj

Creates a router from a vector of provider maps.

Creates a router from a vector of provider maps.
sourceraw docstring

models!clj

Fetches available models from the LLM API.

Fetches available models from the LLM API.
sourceraw docstring

moderation-guardclj

Creates a guard function that uses LLM to check content against policies.

Creates a guard function that uses LLM to check content against policies.
sourceraw docstring

NAMEclj

Field option: Field name as Datomic-style keyword.

Field option: Field name as Datomic-style keyword.
sourceraw docstring

refine!clj

Iteratively refines LLM output using decomposition and verification.

Iteratively refines LLM output using decomposition and verification.
sourceraw docstring

REQUIREDclj

Field option: Whether field is required (default: true).

Field option: Whether field is required (default: true).
sourceraw docstring

reset-budget!clj

Resets the router's token/cost budget counters to zero.

Resets the router's token/cost budget counters to zero.
sourceraw docstring

reset-provider!clj

Manually resets a provider's circuit breaker to :closed.

Manually resets a provider's circuit breaker to :closed.
sourceraw docstring

router-statsclj

Returns cumulative + windowed stats for the router.

Returns cumulative + windowed stats for the router.
sourceraw docstring

sample!clj

Generates test data samples matching a spec with self-correction.

Generates test data samples matching a spec with self-correction.
sourceraw docstring

specclj

Creates a spec definition from field definitions.

Creates a spec definition from field definitions.
sourceraw docstring

spec->promptclj

Generates LLM prompt from a spec.

Generates LLM prompt from a spec.
sourceraw docstring

static-guardclj

Creates a guard function that checks for prompt injection patterns.

Creates a guard function that checks for prompt injection patterns.
sourceraw docstring

str->dataclj

Parses LLM response string to Clojure data.

Parses LLM response string to Clojure data.
sourceraw docstring

str->data-with-specclj

Parses LLM response with spec validation.

Parses LLM response with spec validation.
sourceraw docstring

systemclj

Creates a system message.

Creates a system message.
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.

Field option: Field type.
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 int vector (1 element).

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

TYPE_INT_V_10clj

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

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

TYPE_INT_V_11clj

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

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

TYPE_INT_V_12clj

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

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

TYPE_INT_V_2clj

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

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

TYPE_INT_V_3clj

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

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

TYPE_INT_V_4clj

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

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

TYPE_INT_V_5clj

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

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

TYPE_INT_V_6clj

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

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

TYPE_INT_V_7clj

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

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

TYPE_INT_V_8clj

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

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

TYPE_INT_V_9clj

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

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

TYPE_KEYWORDclj

Type: Clojure keyword.

Type: Clojure keyword.
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.

Field option: Set of allowed nil types.
sourceraw docstring

userclj

Creates a user message, optionally with images.

Creates a user message, optionally with images.
sourceraw docstring

validate-dataclj

Validates parsed data against a spec.

Validates parsed data against a spec.
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