| Schema | Malli | Example |
|---|---|---|
Primitives (s/Int, s/Str, s/Bool, s/Keyword, s/Num) | :int, :string, :boolean, :keyword, :number | (s/def x :- s/Int 42) |
s/maybe | [:maybe ...] | (s/maybe s/Str) -> [:maybe [:string]] |
s/eq | [:= val] | (s/eq 42) -> [:= 42] |
s/enum | [:enum ...] | (s/enum :a :b) -> [:enum :a :b] |
s/either | [:or ...] | (s/either s/Str s/Int) -> [:or [:string] [:int]] |
s/both | [:and ...] | (s/both s/Str (s/pred pos?)) -> [:and [:string] [:fn pos?]] |
s/conditional | [:or ...] | (s/conditional odd? s/Int even? s/Str) |
s/cond-pre | [:or ...] | (s/cond-pre odd? s/Int even? s/Str) |
s/constrained | [:and ...] | (s/constrained s/Int pos? even?) |
s/pred | [:fn ...] | (s/pred pos?) -> [:fn pos?] |
s/=> / s/defn return types | [:-> ...] or [:function ...] | (s/defn f :- s/Str [x :- s/Int] ...) |
| Map destructuring | Validates whole map arg | (s/defn f [{:keys [n]} :- {:n s/Int}] ...) |
| Vector destructuring | Validates vector arg | (s/defn f [[x y] :- [s/Int s/Int]] ...) |
| Nested destructuring | Recursive validation | (s/defn f [{:keys [a] {:keys [b]} :inner} :- ...] ...) |
Rest args (&) | Seq-to-map/vec conversion + validation | (s/defn f [x :- s/Int & {:keys [y]} :- ...] ...) |
:or defaults | {:optional true} on defaulted keys | (s/defn f [{:keys [n] :or {n 0}} :- {:n s/Int}] ...) |
:syms destructuring | Schema keys as quoted symbols | (s/defn f [{x 'x} :- {'x s/Int}] ...) |
| Maps | [:map {:closed true} ...] | {:name s/Str} -> [:map {:closed true} [:name [:string]]] |
| Nested maps | [:map {:closed true} ...] (recursive) | {:user {:id s/Int}} -> [:map {:closed true} [:user [:map {:closed true} [:id [:int]]]]] |
| Vectors | [:vector ...] or [:tuple ...] | [s/Int] -> [:vector [:int]] |
| Sets | [:set ...] | #{s/Int} -> [:set [:int]] |
s/map-of | [:map-of ...] | {s/Int s/Str} -> [:map-of [:int] [:string]] |
s/optional-key | {:optional true} | {(s/optional-key :age) s/Int} |
| Regex patterns | [:re ...] | #"^[A-Z]" -> [:re #"^[A-Z]"] |
schema.core/if | [:or ...] | (schema.core/if string? s/Str s/Int) |
s/recursive | [:schema {:registry ...}] with [:ref ...] | (s/def Tree {:value s/Int :children [(s/recursive #'Tree)]}) |
^{:min 1} metadata | [:int {:min 1}] | Pydantic-style validation |
Note: s/either and s/both are deprecated in schema.core (replaced s/either with s/conditional or s/cond-pre, and replaced s/both with s/conditional with one condition), but Schemallic supports them fully. If you're migrating legacy code that uses them, they'll convert cleanly.
schema.core/if is not re-exported by schemallic.core; require schema.core directly when you need it.
s/cond-pre, s/conditional)s/cond-pre and s/conditional both convert to [:or ...] with each branch wrapped in [:and [:fn pred] schema]:
;; Prismatic
(s/cond-pre integer? s/Int #(contains? % :a) {:a s/Str})
;; Malli
[:or [:and [:fn integer?] [:int]]
[:and [:fn #(contains? % :a)] [:map {:closed true} [:a [:string]]]]]
The [:and [:fn pred] schema] representation preserves the original predicate for inspection and error reporting. Each branch requires both the predicate and schema to pass — the predicate acts as a type discriminator, and the schema validates the structure.
Important: Predicates must be type discriminators, not value comparators. The [:fn pred] is applied to the raw value, so the predicate must handle the actual value type:
| Predicates that work | Predicates that break |
|---|---|
integer?, string?, map? | #(>= % 2000) on a map value |
#(contains? % :key) | #(= % :specific-value) on a non-matching type |
pos?, even? on numbers | — |
If you need value-based branching inside a schema field, use s/constrained instead:
;; Instead of this (breaks):
(s/conditional #(>= % 2000) {:value s/Int} #(< % 2000) s/Int)
;; Do this (works):
(s/constrained s/Int #(>= % 2000))
s/recursive)s/recursive self-references (tree structures, linked lists, etc.) convert to a self-contained Malli [:schema {:registry ...}] form. The first occurrence of a recursive var wraps its converted body in a registry; self-references inside the body become [:ref key]:
;; Prismatic
(s/def Tree {:value s/Int
:children [(s/recursive #'Tree)]})
;; Malli
[:map {:closed true}
[:value [:int]]
[:children
[:vector
[:schema
{:registry {:my.ns/Tree [:map {:closed true}
[:value [:int]]
[:children [:vector [:ref :my.ns/Tree]]]]}}
:my.ns/Tree]]]]
The registry key is derived from the referenced var's namespace and name, so recursive references resolve locally without a global registry. s/recursive must reference a var (e.g. #'Tree); passing a non-var derefable throws.
Schema s/Inst and s/Num have no built-in Malli equivalent, so Schemallic registers :inst and :number as custom types on top of Malli's default registry:
| Schema | Malli | Registered? |
|---|---|---|
s/Inst | :inst | yes (custom) |
s/Num | :number | yes (custom) |
schemallic.malli uses default-malli-registry automatically. Pass it explicitly only for raw Malli APIs such as m/validate, m/explain, and malli.generator/generator. If you prefer to keep these types out of your registry, build your own composite:
(require '[malli.core :as m]
'[malli.registry :as mr])
(def my-registry
(mr/composite-registry
{:inst (m/-simple-schema {:type :inst :pred inst?})
:number (m/-simple-schema {:type :number :pred number?})}
(mr/schemas m/default-registry)))
(m/validate [:map [:x :number]] {:x 1} {:registry my-registry})
These schema.core features are not converted and will throw:
| Feature | Reason |
|---|---|
s/defrecord (record schemas) | Malli has its own record support |
s/protocol (protocol schemas) | Not a validation concern |
Java classes (Color, File, Thread) | Not a validation pattern |
Protocol interfaces (IFn, ISeq) | Not a validation pattern |
Mixed sets (#{s/Bool s/Uuid s/Inst}) | Use :or instead |
Mixed vectors with literals ([s/Str "foo" 42]) | Use :tuple or :or |
Custom reify schemas | No Malli equivalent |
schema.core coercion matchers | Not supported; use Malli-backed schemallic.malli coercion instead |
Can you improve this documentation?Edit on GitHub
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 |