# Code argument when raising validation errors

**URL:** <https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315>\
**Category:** Forms & APIs\
**Created:** [June 11, 2021, 5:44pm UTC](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315 "2021-06-11T17:44:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![run\_the\_race](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/run_the_race/32/4822_2.png) [@run\_the\_race](https://forum.djangoproject.com/u/run_the_race)\
**Post date:** [June 11, 2021, 5:44pm UTC](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315/1 "2021-06-11T17:44:27Z")

</div>

In the [validation docs](https://docs.djangoproject.com/en/3.2/ref/forms/validation/#raising-validationerror) it talks about it being good practice to pass in a `code` argument when raising a `ValidationError`. Where do these codes come from? Is there a list of them? Should I just make up my own codes as what seems appropiate?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 11, 2021, 6:53pm UTC](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315/2 "2021-06-11T18:53:27Z")

</div>

Yes, you make up your own codes. The codes provide a way for other modules to know what errors were thrown and possibly take direct action. You don’t want to rely only upon the text of the message because it could be translated into different languages or there might be variables put into the error text.

---

<div class="post-metadata">

**Author:** ![vlt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vlt/32/31767_2.png) [@vlt](https://forum.djangoproject.com/u/vlt)\
**Post date:** [March 13, 2026, 11:25am UTC](https://forum.djangoproject.com/t/code-argument-when-raising-validation-errors/8315/3 "2026-03-13T11:25:35Z")

</div>

> <https://github.com/django/django/blob/d43bd466e93aad7df13bb94fda4d01bc63b76a45/django/forms/fields.py#L195-L196>

One day, this^^^ might cause you at least two hours of trouble shooting when you can’t find out why your carefully hand crafted validation error message doesn’t appear in the form errors 😉
