> ## 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.

# String

> String fields with length, pattern, and format constraints.

Use `"type": "string"` for free-form text fields. Then add constraints to control size, format, and allowed values.

## Supported keywords

| Keyword                   | What it does                           |
| ------------------------- | -------------------------------------- |
| `type: "string"`          | Declares a text field                  |
| `minLength` / `maxLength` | Bounds text length                     |
| `pattern`                 | Enforces a regex                       |
| `format`                  | Semantic format check (`email`, `uri`) |

## Length constraints

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "username": {
        "type": "string",
        "minLength": 3,
        "maxLength": 120
      }
    },
    "required": ["username"],
    "additionalProperties": false
  }
  ```

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

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

      username: Annotated[str, StringConstraints(min_length=3, max_length=120)]
  ```

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

  const payloadSchema = z
    .object({
      username: z.string().min(3).max(120),
    })
    .strict();
  ```
</CodeGroup>

Use this to avoid empty outputs and cap long generations. The length bounds are inclusive.

## Pattern constraints

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "country_code": {
        "type": "string",
        "pattern": "^[A-Z]{2}$"
      }
    },
    "required": ["country_code"],
    "additionalProperties": false
  }
  ```

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

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

      country_code: Annotated[str, StringConstraints(pattern=r"^[A-Z]{2}$")]
  ```

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

  const payloadSchema = z
    .object({
      country_code: z.string().regex(/^[A-Z]{2}$/),
    })
    .strict();
  ```
</CodeGroup>

This matches exactly two uppercase letters (for example country codes).

## Format constraints

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "email": { "type": "string", "format": "email" },
      "website": { "type": "string", "format": "uri" }
    },
    "required": ["email", "website"],
    "additionalProperties": false
  }
  ```

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

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

      email: EmailStr
      website: AnyUrl
  ```

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

  const payloadSchema = z
    .object({
      email: z.string().email(),
      website: z.string().url(),
    })
    .strict();
  ```
</CodeGroup>

Formats are named patterns that validate well-known string shapes. The following formats are currently supported:

| Format            | Description                       | Example of Accepted Value                |
| ----------------- | --------------------------------- | ---------------------------------------- |
| `date-time`       | RFC 3339 date-time                | `"2026-03-23T14:30:00Z"`                 |
| `date`            | RFC 3339 date                     | `"2026-03-23"`                           |
| `date-time-local` | Date-time without timezone        | `"2026-03-23T14:30:00"`                  |
| `time`            | RFC 3339 time with timezone       | `"14:30:00Z"`                            |
| `time-local`      | Time without timezone             | `"14:30:00"`                             |
| `duration`        | ISO 8601 duration                 | `"P3Y6M4DT12H30M5S"`                     |
| `unixtime`        | Seconds since Unix epoch          | `"1742739000"`                           |
| `utc-millisec`    | Milliseconds since Unix epoch     | `"1742739000000"`                        |
| `email`           | RFC 5321 email address            | `"alice@example.com"`                    |
| `uuid`            | RFC 9562 UUID                     | `"550e8400-e29b-41d4-a716-446655440000"` |
| `uri`             | RFC 3986 URI                      | `"https://example.com/path"`             |
| `uri-reference`   | URI or relative reference         | `"/path/to/resource"`                    |
| `uri-template`    | RFC 6570 URI template             | `"https://example.com/{id}"`             |
| `url`             | Full URL with scheme              | `"https://example.com"`                  |
| `hostname`        | RFC 1123 hostname                 | `"example.com"`                          |
| `ipv4`            | IPv4 address                      | `"192.168.1.1"`                          |
| `ipv6`            | IPv6 address                      | `"::1"`                                  |
| `byte`            | Base64-encoded string             | `"SGVsbG8="`                             |
| `double`          | Double-precision float as string  | `"3.141592653589793"`                    |
| `double-int`      | Integer stored as double          | `"42"`                                   |
| `float`           | Single-precision float as string  | `"3.14"`                                 |
| `int8`            | Integer in \[-128, 127]           | `"42"`                                   |
| `int16`           | Integer in \[-32768, 32767]       | `"1000"`                                 |
| `int32`           | Integer in \[-2³¹, 2³¹-1]         | `"100000"`                               |
| `int64`           | Integer in \[-2⁶³, 2⁶³-1]         | `"9999999999"`                           |
| `uint8`           | Integer in \[0, 255]              | `"200"`                                  |
| `uint16`          | Integer in \[0, 65535]            | `"50000"`                                |
| `uint32`          | Integer in \[0, 2³²-1]            | `"3000000000"`                           |
| `uint64`          | Integer in \[0, 2⁶⁴-1]            | `"10000000000"`                          |
| `decimal`         | Arbitrary-precision decimal       | `"99.95"`                                |
| `decimal128`      | IEEE 754 decimal128               | `"12345.6789012345"`                     |
| `sf-binary`       | RFC 8941 structured field binary  | `":SGVsbG8=:"`                           |
| `sf-boolean`      | RFC 8941 structured field boolean | `"?1"`                                   |
| `sf-decimal`      | RFC 8941 structured field decimal | `"3.14"`                                 |
| `sf-integer`      | RFC 8941 structured field integer | `"42"`                                   |
| `sf-string`       | RFC 8941 structured field string  | `"\"hello\""`                            |
| `sf-token`        | RFC 8941 structured field token   | `"abc"`                                  |
| `expose`          | Any string (no validation)        | `"anything"`                             |

## Related

* [Object reference](/json-schema/reference/object)
* [Composition reference](/json-schema/reference/composition)
* [String Bounds cookbook](/json-schema/string-bounds)
