# Get keys instead of sentences for validation errors

**URL:** <https://discourse.dry-rb.org/t/get-keys-instead-of-sentences-for-validation-errors/150>\
**Category:** dry-validation\
**Created:** [November 5, 2016, 4:42pm UTC](https://discourse.dry-rb.org/t/get-keys-instead-of-sentences-for-validation-errors/150 "2016-11-05T16:42:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnd](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dnd/32/66_2.png) [@dnd](https://discourse.dry-rb.org/u/dnd)\
**Post date:** [November 5, 2016, 4:42pm UTC](https://discourse.dry-rb.org/t/get-keys-instead-of-sentences-for-validation-errors/150/1 "2016-11-05T16:42:59Z")

</div>

I have an API where I am wanting to just return the error symbols/keys rather than sentences/text when validation fails. Something along the lines of `{amount: [:missing, :min_size]}` or maybe `{amount: {missing: {text: 'is missing'}, size: {left: 0, right: 1000, text: 'must be between 0 and 1000'}}`. Is this possible to do currently in dry-validation?

Thanks,  
Steve

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [November 9, 2016, 9:04pm UTC](https://discourse.dry-rb.org/t/get-keys-instead-of-sentences-for-validation-errors/150/2 "2016-11-09T21:04:26Z")

</div>

You have two options:

1. Implement a custom message compiler by subclassing [this built in one](https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/message_compiler.rb) - this is more advanced but it will give you complete control over the structure that’s returned by validation result
2. Simply use `Dry::Validation::Result#message_set` and see if you have enough information in the message objects to map them to the structure that you want to have. ie `schema.(params).message_set(hints: false).map { |msg| ... }` would yield error message objects to the block and you can do whatever you want there

Lemme know which one sounds like a better fit.
