diff --git a/src/content/docs/en/guides/actions.mdx b/src/content/docs/en/guides/actions.mdx
index fa2bec9393f5b..9a5c00ff1d26c 100644
--- a/src/content/docs/en/guides/actions.mdx
+++ b/src/content/docs/en/guides/actions.mdx
@@ -24,7 +24,7 @@ Actions are defined in a `server` object exported from `src/actions/index.ts`:
```ts title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
myAction: defineAction({ /* ... */ })
@@ -62,11 +62,11 @@ Follow these steps to define an action and call it in a `script` tag in your Ast
}
```
-2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro:schema`.
+2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro/zod`.
```ts ins={1-2} title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
- import { z } from 'astro:schema';
+ import { z } from 'astro/zod';
export const server = {
// action declarations
@@ -77,7 +77,7 @@ Follow these steps to define an action and call it in a `script` tag in your Ast
```ts ins={5-12} title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
- import { z } from 'astro:schema';
+ import { z } from 'astro/zod';
export const server = {
getGreeting: defineAction({
@@ -213,7 +213,7 @@ This example throws an error from a `likePost` action when a user is not logged
```ts title="src/actions/index.ts" ins=/ActionError(?= )/ ins={9-12}
import { defineAction, ActionError } from "astro:actions";
-import { z } from "astro:schema";
+import { z } from "astro/zod";
export const server = {
likePost: defineAction({
@@ -290,7 +290,7 @@ Actions accept JSON data by default. To accept form data from an HTML form, set
```ts title="src/actions/index.ts" ins={6}
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
comment: defineAction({
@@ -319,7 +319,7 @@ To apply a union of different validators, use the `z.discriminatedUnion()` wrapp
```ts title="src/actions/index.ts" {7-21} "create" "update"
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
changeUser: defineAction({
@@ -378,7 +378,7 @@ The following example shows a validated newsletter registration form that accept
```ts title="src/actions/index.ts" ins={5-12}
import { defineAction } from 'astro:actions';
- import { z } from 'astro:schema';
+ import { z } from 'astro/zod';
export const server = {
newsletter: defineAction({
@@ -492,7 +492,7 @@ For example, say you have a `createProduct` action that returns the generated pr
```ts title="src/actions/index.ts" mark={10}
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
createProduct: defineAction({
diff --git a/src/content/docs/en/guides/astro-db.mdx b/src/content/docs/en/guides/astro-db.mdx
index 647a37c77d53d..c2642ec763152 100644
--- a/src/content/docs/en/guides/astro-db.mdx
+++ b/src/content/docs/en/guides/astro-db.mdx
@@ -401,7 +401,7 @@ You can also use [Astro actions](/en/guides/actions/) to insert data into an Ast
// src/actions/index.ts
import { db, Comment } from 'astro:db';
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
addComment: defineAction({
diff --git a/src/content/docs/en/guides/content-collections.mdx b/src/content/docs/en/guides/content-collections.mdx
index 3ddbb82a57cd9..7325caabae5c3 100644
--- a/src/content/docs/en/guides/content-collections.mdx
+++ b/src/content/docs/en/guides/content-collections.mdx
@@ -63,8 +63,9 @@ Individual collections use `defineCollection()` to configure:
To define collections, you must create a `src/content.config.ts` file in your project (`.js` and `.mjs` extensions are also supported.) This is a special file that Astro will use to configure your content collections based on the following structure:
```ts title="src/content.config.ts"
-// 1. Import utilities from `astro:content`
-import { defineCollection, z } from 'astro:content';
+// 1. Import utilities from `astro:content` and `astro/zod`
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
// 2. Import loader(s)
import { glob, file } from 'astro/loaders';
@@ -89,8 +90,9 @@ The [`glob()` loader](/en/reference/content-loader-reference/#glob-loader) creat
The [`file()` loader](/en/reference/content-loader-reference/#file-loader) creates multiple entries from a single local file. Each entry in the file must have a unique `id` key property. It accepts a `base` file path to your file and optionally a [`parser` function](#parser-function) for data files it cannot parse automatically. Use this loader when your data file can be parsed as an array of objects.
-```ts title="src/content.config.ts" {5,9}
-import { defineCollection, z } from 'astro:content';
+```ts title="src/content.config.ts" {6,10}
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders'; // Not available with legacy API
const blog = defineCollection({
@@ -210,8 +212,9 @@ In order for Astro to recognize a new or updated schema, you may need to restart
Every frontmatter or data property of your collection entries must be defined using a Zod data type:
-```ts title="src/content.config.ts" {6-11,15-19}
-import { defineCollection, z } from 'astro:content';
+```ts title="src/content.config.ts" {7-12,16-20}
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders'; // Not available with legacy API
const blog = defineCollection({
@@ -243,7 +246,8 @@ To use Zod in Astro, import the `z` utility from `"astro:content"`. This is a re
```ts
// Example: A cheatsheet of many common Zod datatypes
-import { z, defineCollection } from 'astro:content';
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
defineCollection({
schema: z.object({
@@ -286,7 +290,8 @@ With the [`reference()` function](/en/reference/modules/astro-content/#reference
A common example is a blog post that references reusable author profiles stored as JSON, or related post URLs stored in the same collection:
```ts title="src/content.config.ts"
-import { defineCollection, reference, z } from 'astro:content';
+import { defineCollection, reference } from 'astro:content';
+import { z } from 'astro/zod';
import { glob } from 'astro/loaders';
const blog = defineCollection({
diff --git a/src/content/docs/en/guides/images.mdx b/src/content/docs/en/guides/images.mdx
index 91fbbbec33997..fa38b308a1ecb 100644
--- a/src/content/docs/en/guides/images.mdx
+++ b/src/content/docs/en/guides/images.mdx
@@ -590,7 +590,8 @@ This is a blog post
The `image` helper for the content collections schema lets you validate and import the image.
```ts title="src/content.config.ts"
-import { defineCollection, z } from "astro:content";
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
const blogCollection = defineCollection({
schema: ({ image }) => z.object({
diff --git a/src/content/docs/en/guides/integrations-guide/mdx.mdx b/src/content/docs/en/guides/integrations-guide/mdx.mdx
index 8848e087aa998..cdf3eee96b3fb 100644
--- a/src/content/docs/en/guides/integrations-guide/mdx.mdx
+++ b/src/content/docs/en/guides/integrations-guide/mdx.mdx
@@ -101,7 +101,8 @@ It also adds extra features to standard MDX, including support for Markdown-styl
To include MDX files in a content collection, make sure that your [collection loader](/en/guides/content-collections/#defining-the-collection-loader) is configured to load content from `.mdx` files:
```js title="src/content.config.ts" ins="mdx"
-import { defineCollection, z } from 'astro:content';
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob } from 'astro/loaders';
const blog = defineCollection({
diff --git a/src/content/docs/en/guides/integrations-guide/react.mdx b/src/content/docs/en/guides/integrations-guide/react.mdx
index 45b238fbbcd1a..6a0c70ddfc4f7 100644
--- a/src/content/docs/en/guides/integrations-guide/react.mdx
+++ b/src/content/docs/en/guides/integrations-guide/react.mdx
@@ -167,7 +167,7 @@ The example below gets the current value of likes from a counter, typed as a num
```ts title="actions.ts" ins={3,11}
import { defineAction, type SafeResult } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
import { getActionState } from '@astrojs/react/actions';
export const server = {
diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx
index bde6ae485f064..7f2d333af26a3 100644
--- a/src/content/docs/en/guides/sessions.mdx
+++ b/src/content/docs/en/guides/sessions.mdx
@@ -90,7 +90,7 @@ In actions, the session object is available on the `context` object. For example
```ts title="src/actions/addToCart.ts" "context.session"
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
addToCart: defineAction({
diff --git a/src/content/docs/en/guides/upgrade-to/v6.mdx b/src/content/docs/en/guides/upgrade-to/v6.mdx
index 59b159dff19e9..ecb35a002c4fb 100644
--- a/src/content/docs/en/guides/upgrade-to/v6.mdx
+++ b/src/content/docs/en/guides/upgrade-to/v6.mdx
@@ -155,6 +155,31 @@ someLogic(build.assetsPrefix)
Read more about the [`astro:config` virtual modules](/en/reference/modules/astro-config/).
+### Deprecated: `astro:schema` and `z` from `astro:content`
+
+
+
+In Astro 5.x, `astro:schema` was introduced as an alias of `astro/zod`. `z` was also exported from `astro:content` for convenience. However that created confusion for users who did not know what to import from where.
+
+Astro 6.0 deprecates `astro:schema` and `z` from `astro:content` in favor of `astro/zod`.
+
+#### What should I do?
+
+Replace any occurrences of `astro:schema` with `astro/zod`:
+
+```ts del={1} ins={2}
+import { z } from "astro:schema"
+import { z } from "astro/zod"
+```
+
+Check your `astro:content` imports and update them if you import `z`:
+
+```ts title="src/content.config.ts" del={1} ins={2-3}
+import { defineCollection, z } from "astro:content"
+import { defineCollection } from "astro:content"
+import { z } from "astro/zod"
+```
+
## Removed
The following features have now been entirely removed from the code base and can no longer be used. Some of these features may have continued to work in your project even after deprecation. Others may have silently had no effect.
@@ -207,9 +232,10 @@ Rename and move this file to `src/content.config.ts`
Import [Astro's built-in `glob()` loader](/en/guides/content-collections/#built-in-loaders) and define the `pattern` and `base` for your collection entries:
-```ts ins={3,6}
+```ts ins={4,7}
// src/content.config.ts
-import { defineCollection, z } from 'astro:content';
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob } from 'astro/loaders';
const blog = defineCollection({
@@ -228,9 +254,10 @@ const blog = defineCollection({
a collection that defines a collection type (`type: 'content'` or `type: 'data'`) / ([`ContentCollectionInvalidTypeError`](/en/reference/errors/content-collection-invalid-type/))
There are no longer different types of collections. This must be deleted from your collection definition.
-```ts del={7}
+```ts del={8}
// src/content.config.ts
-import { defineCollection, z } from 'astro:content';
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob } from 'astro/loaders';
const blog = defineCollection({
diff --git a/src/content/docs/en/recipes/i18n.mdx b/src/content/docs/en/recipes/i18n.mdx
index 8e4f12cc7859f..6d7b702676795 100644
--- a/src/content/docs/en/recipes/i18n.mdx
+++ b/src/content/docs/en/recipes/i18n.mdx
@@ -87,7 +87,8 @@ If you prefer the default language to not be visible in the URL unlike other lan
```ts
//src/content.config.ts
- import { defineCollection, z } from 'astro:content';
+ import { defineCollection } from 'astro:content';
+ import { z } from 'astro/zod';
const blogCollection = defineCollection({
schema: z.object({
diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx
index 14a119663d97b..9a99e7965b7ee 100644
--- a/src/content/docs/en/reference/content-loader-reference.mdx
+++ b/src/content/docs/en/reference/content-loader-reference.mdx
@@ -183,7 +183,7 @@ The recommended pattern is to define a function that accepts configuration optio
```ts title=loader.ts
import type { Loader, LoaderContext } from 'astro/loaders';
-import { z } from 'astro:content';
+import { z } from 'astro/zod';
import { loadFeedData } from "./feed.js";
// Define any options that the loader needs
@@ -209,8 +209,9 @@ export function myLoader(options: { url: string, apiKey: string }): Loader {
These configuration options can then be set when defining a collection:
-```ts title="src/content.config.ts" {2,5-8}
-import { defineCollection, z } from 'astro:content';
+```ts title="src/content.config.ts" {3,6-9}
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import myLoader from '../../loader.ts';
const blog = defineCollection({
diff --git a/src/content/docs/en/reference/experimental-flags/live-content-collections.mdx b/src/content/docs/en/reference/experimental-flags/live-content-collections.mdx
index 2d6c7aa72604e..8e2b2356bd070 100644
--- a/src/content/docs/en/reference/experimental-flags/live-content-collections.mdx
+++ b/src/content/docs/en/reference/experimental-flags/live-content-collections.mdx
@@ -487,7 +487,8 @@ if (error) {
Just like with build-time collections, you can use [Zod schemas](/en/guides/content-collections/#defining-the-collection-schema) with live collections to validate and transform data at runtime. When you define a schema, it takes precedence over [the loader's types](#type-safe-data) when you query the collection:
```ts title="src/live.config.ts"
-import { z, defineLiveCollection } from 'astro:content';
+import { defineLiveCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { apiLoader } from './loaders/api-loader';
const products = defineLiveCollection({
diff --git a/src/content/docs/en/reference/modules/astro-actions.mdx b/src/content/docs/en/reference/modules/astro-actions.mdx
index 7d85ab5af3a03..145cc883727d6 100644
--- a/src/content/docs/en/reference/modules/astro-actions.mdx
+++ b/src/content/docs/en/reference/modules/astro-actions.mdx
@@ -42,7 +42,7 @@ A utility to define new actions in the `src/actions/index.ts` file. This accepts
```ts title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
-import { z } from 'astro:schema';
+import { z } from 'astro/zod';
export const server = {
getGreeting: defineAction({
diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx
index cc72bd2d2a523..0d7eb9d95c313 100644
--- a/src/content/docs/en/reference/modules/astro-content.mdx
+++ b/src/content/docs/en/reference/modules/astro-content.mdx
@@ -18,7 +18,6 @@ Content collections offer APIs to configure and query your Markdown or MDX docum
```js
import {
- z,
defineCollection,
getCollection,
getEntry,
@@ -38,7 +37,8 @@ import {
`defineCollection()` is a utility to configure a collection in a `src/content.config.*` file.
```ts title="src/content.config.ts"
-import { z, defineCollection } from 'astro:content';
+import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { glob } from 'astro/loaders';
const blog = defineCollection({
@@ -94,7 +94,8 @@ The `reference()` function is used in the content config to define a relationshi
This example defines references from a blog author to the `authors` collection and an array of related posts to the same `blog` collection:
```ts
-import { defineCollection, reference, z } from 'astro:content';
+import { defineCollection, reference } from 'astro:content';
+import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders';
const blog = defineCollection({
@@ -304,7 +305,8 @@ This includes the following property:
- `image` - The `image()` schema helper that allows you [to use local images in Content Collections](/en/guides/images/#images-in-content-collections)
```ts
-import { defineCollection, z, type SchemaContext } from "astro:content";
+import { defineCollection, type SchemaContext } from 'astro:content';
+import { z } from 'astro/zod';
export const imageSchema = ({ image }: SchemaContext) =>
z.object({