Strict Mode

Strict mode ensures the model strictly follows the JSON Schema format when generating function calls.

Strict mode ensures the model strictly follows the JSON Schema format when generating function calls. When enabled, the SDK automatically:

  1. Sends the request to the DeepSeek Beta endpoint (https://api.deepseek.com/beta)
  2. Passes strict: true in all tool definitions to the API
  3. Enforces that all object properties are required and sets additionalProperties: false

The server validates the JSON Schema and returns an error if it doesn't conform to the supported schema types.

There are two ways to enable strict mode:

Set strict: true on the model to enable strict mode for all tool calls globally:

const model = createModel({ model: 'deepseek-v4-flash', strict: true })

When using model-level strict, all tools in requests will automatically have strict: true — you don't need to set it on each tool individually. The SDK also automatically switches to the Beta endpoint via model.enableBeta().

You can also manually trigger Beta endpoint switching:

const model = createModel({ model: 'deepseek-v4-flash' })
model.enableBeta() // Switches baseURL to https://api.deepseek.com/beta/

Per-Tool Strict

Set strict: true on individual tools. All tools in the same request must have the same strict value — mixing strict and non-strict tools is not allowed:

const searchTool = tool({
  name: 'search',
  description: 'Search records in the database',
  schema: z.object({
    query: z.string().describe('Search keywords'),
    limit: z.number().describe('Maximum number of results'),
  }),
  strict: true,
  execute: async (input) => {
    return { results: [], total: 0 }
  },
})

When any tool has strict: true, the SDK automatically detects this and switches to the Beta endpoint before sending the request.

Type Safety

TypeScript enforces consistency at compile time through dedicated types:

  • StrictTool[] — All tools must have strict: true
  • NonStrictTool[] — All tools have strict: false or undefined
  • ConsistentTools = StrictTool[] | NonStrictTool[] — Union type used by generateText and agent methods

A runtime validation via validateToolConsistency() is also performed as a fallback, throwing an error if strict and non-strict tools are mixed.

Supported JSON Schema Types

Strict mode supports a subset of JSON Schema types. Using unsupported types will result in a server-side error:

TypeNotes
objectAll properties must be required; additionalProperties must be false
stringSupports pattern, format (email, hostname, ipv4, ipv6, uuid); no minLength/maxLength
number / integerSupports minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, const, default
booleanFully supported
arrayNo minItems/maxItems support
enumFully supported
anyOfFully supported for union types
$ref / $defSupported for modular schemas and recursive structures