Filter parameters

Upstream URL


Eitaro Fukamachi


BSD 2-Clause


Build Status Coverage Status Quicklisp dist

Safety-Params is for checking values.

Upgrading Notes to v0.3.0

This library is used to be called "Sanitized-Params" which is designed to sanitize, which means it doesn't raise any errors and just omits key-values even when the specified condition has failed.

However, it has been commonly used mainly for validating values. That made me decide to revise its APIs and give 2 macros, sanitize and validate.

Additionally, I found that value-conversions are often following after a validation. For instance, a code expecting an integer but its input could be a string.

Since v0.3.0, the value-conversions features were added:

  (satisfies "amount" (being integer)))
 '(("amount" . "108")))
;=> (("amount" . 108))  <- Implicit conversion "108" -> 108


Checking values


 (list-of #'integerp)
 '(1 2 3))
;=> (1 2 3)

 (list-of #'integerp)
 '(1 2 "3" 4))
;-> ASSERTION-FAILD: Assertion #<FUNCTION INTEGERP> for (1 2 "3" 4) failed

Association List

(defvar *params*
  '(("id" . "4e3c89aa-4244-4014-ae36-dfaf1dc969f5")
    ("amount" . 10)))

;; Validating key-values
  (satisfies "id" #'stringp)
  (satisfies "amount" #'integerp))

;; Checking permitted key-values
  (permits "id" "amount"))

;; Checking required key-values
  (requires "id"))

Nested example

  (requires "name")
  (satisfies "email" #'listp)
  (satisfies "friends"
               (requires "name")
               (satisfies "family" (list-of
                                    (alist (permits "name"))))
               (satisfies "hobbies" #'listp)))))
 '(("name" . "Eitaro Fukamachi")
   ("email" . ("" ""))
   ("friends" . ((("name" . "Masatoshi Sano")
                  ("family" . ())
                  ("hobbies" . ("rocket" "lisp")))))))
;=> (("name" . "Eitaro Fukamachi") ("email" "" "")
;    ("friends" (("name" . "Masatoshi Sano") ("family") ("hobbies" "rocket" "lisp"))))

Converting values

 (list-of (being integer))
 '(1 2 "3" 4))
;=> (1 2 3 4)

Custom error message

Safety-params provides (setf validation-message) function to set a custom error message which will be shown when the validation has failed.

(setf (validation-message 'zero-string-p)
      "Must be zero in string")

It also allows to set with satisfies by specifying an optional :message argument.

  (satisfies "amount" #'zero-string-p
             :message "Must be zero in string"))
 '(("amount" . "-2")))
;-> Validation errors:
;     Invalid:
;       - amount (Must be zero in string)
;    [Condition of type VALIDATION-ERROR]

Sanitizing values

 (list-of #'integerp)
 '(1 2 "3" 4))
;=> (1 2 4)



Copyright (c) 2016 Eitaro Fukamachi (


Licensed under the BSD 2-Clause License.

Dependencies (3)

  • alexandria
  • parse-number
  • rove

Dependents (0)

    • GitHub
    • Quicklisp