Return error codes/keys instead of text

I’m trying to use dry-validation with an API where I return codes like blank, inclusion, invalid and I wonder if I can achieve the same with dry-validation.

There’s a really old thread here about this: Get keys instead of sentences for validation errors

But that looks outdated. Is there any new way to get those?

This is supported. Here’s a spec that shows the usage. If you’ve found any issues please report it.

This works for rules only, right?
Or is it possible to do the same for required/optional of a schema?

One way to achieve that is by getting the error list from and changing that to a format like:

        text: "must be an array"
          code: :array

        text: "must be empty"
          code: :empty

Then you just add your yml to the dry-validation config, as in the last example from

Thanks! There is a slight discrepancy between schema and rules but I can live with it for now:

{:age=>[{:text=>"...", :meta=>{"code"=>"..."}}]
{:age=>[{:text=>"...", :code=>"...", :input=>"..."}]

In rules I can also add additional context, for example the input which can be useful for debugging. It would be great if schema and rules would work the same here.

I might try to use an own backend as a (temporarily) solution.