> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dottxt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Enum

> Restrict a value to a fixed set of choices.

Use `enum` to restrict a field to a list of allowed values.

## Basic usage

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "priority": { "enum": ["low", "medium", "high"] },
      "status": { "enum": ["open", "in_progress", "closed"] }
    },
    "required": ["priority", "status"],
    "additionalProperties": false
  }
  ```

  ```python Pydantic theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  from typing import Literal
  from pydantic import BaseModel, ConfigDict

  class Payload(BaseModel):
      model_config = ConfigDict(extra="forbid")

      priority: Literal["low", "medium", "high"]
      status: Literal["open", "in_progress", "closed"]
  ```

  ```typescript Zod theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import { z } from "zod";

  const payloadSchema = z
    .object({
      priority: z.enum(["low", "medium", "high"]),
      status: z.enum(["open", "in_progress", "closed"]),
    })
    .strict();
  ```
</CodeGroup>

Use enums for categories and statuses so outputs stay predictable.

## Mixed-type enums

`enum` values are not restricted to strings:

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "score": { "enum": [1, 2, 3, "unknown", null] }
    },
    "required": ["score"],
    "additionalProperties": false
  }
  ```

  ```python Pydantic theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  from typing import Literal
  from pydantic import BaseModel, ConfigDict

  class Payload(BaseModel):
      model_config = ConfigDict(extra="forbid")

      score: Literal[1, 2, 3, "unknown"] | None
  ```

  ```typescript Zod theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import { z } from "zod";

  const payloadSchema = z
    .object({
      score: z.union([
        z.literal(1),
        z.literal(2),
        z.literal(3),
        z.literal("unknown"),
        z.null(),
      ]),
    })
    .strict();
  ```
</CodeGroup>

For single-value enums, use [const](/json-schema/reference/const) instead.

## Related

* [Const reference](/json-schema/reference/const)
* [String reference](/json-schema/reference/string)
