Skip to content
Back to skills

Clojure Guardrails

ASecurity

Reference for Guardrails library with Malli in Clojure. Use when working with `>defn`, `>defn-`, `>def`, `>fdef` macros, gspec syntax, or function validation. Triggers on guardrails imports, `com.fulcrologic.guardrails.malli`, function specs with `=>` operator, or questions about runtime validation in Clojure.

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 8, 2026
documentationbashrailsdocumentation

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill clojure-guardrails --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clojure Guardrails?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clojure Guardrails
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-clojure-guardrails/badge)](https://www.skillsdirectory.com/skills/majiayu000-clojure-guardrails)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: clojure-guardrails
description: Reference for Guardrails library with Malli in Clojure. Use when working with `>defn`, `>defn-`, `>def`, `>fdef` macros, gspec syntax, or function validation. Triggers on guardrails imports, `com.fulcrologic.guardrails.malli`, function specs with `=>` operator, or questions about runtime validation in Clojure.
---

# Clojure Guardrails (Malli)

## Detection

Check if guardrails is in use:
```bash
grep -r "guardrails.enabled" deps.edn shadow-cljs.edn 2>/dev/null
```

## Setup

**deps.edn:**
```clojure
{:deps {com.fulcrologic/guardrails {:mvn/version "1.2.16"}
        metosin/malli             {:mvn/version "0.20.0"}}
 :aliases {:dev {:jvm-opts ["-Dguardrails.enabled=true"]}}}
```

See https://clojars.org/com.fulcrologic/guardrails for the latest version.

**Enable at runtime:** `-Dguardrails.enabled=true`

## Import

```clojure
(require '[com.fulcrologic.guardrails.malli.core :refer [>defn >defn- >def >fdef | ? =>]])
```

## Core Macros

| Macro | Purpose |
|-------|---------|
| `>defn` | Define function with inline spec |
| `>defn-` | Private function with spec |
| `>def` | Register malli schema |
| `>fdef` | Declare spec without body |
| `?` | Nilable shorthand `[:maybe schema]` |
| `\|` | "Such that" constraints |
| `=>` | Separates args from return |

## Gspec Syntax

```
[arg-specs* (| arg-preds+)? => ret-spec (| ret-preds+)?]
```

**Basic:**
```clojure
(>defn add [a b]
  [:int :int => :int]
  (+ a b))
```

**With constraints:**
```clojure
(>defn ranged-rand [start end]
  [:int :int | #(< start end)
   => :int | #(>= % start) #(< % end)]
  (+ start (long (rand (- end start)))))
```

**Nilable:**
```clojure
(>defn find-user [id]
  [:int => (? :map)]
  (get users id))
```

**Multi-arity:**
```clojure
(>defn greet
  ([name]
   [:string => :string]
   (str "Hello, " name))
  ([greeting name]
   [:string :string => :string]
   (str greeting ", " name)))
```

**Variadic:**
```clojure
(>defn sum [x & more]
  [:int [:* :int] => :int]
  (apply + x more))
```

**Map schemas:**
```clojure
(>defn process-user [user]
  [[:map [:name :string] [:age :int]] => :string]
  (str (:name user) " is " (:age user)))
```

## Schema Registry

This is an optional feature.

```clojure
(require '[com.fulcrologic.guardrails.malli.registry :as gr.reg])

;; Register schemas
(>def :user/name :string)
(>def :user/age :int)
(>def :user/record [:map :user/name :user/age])

;; Use in functions
(>defn get-user [id]
  [:int => (? :user/record)]
  (lookup id))
```

## Detailed Reference

See [gspec-syntax.md](references/gspec-syntax.md) for complete syntax documentation.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.