Schema Definition
The complete schema is defined insrc/content/config.ts:3:
words-es- Spanish wordswords-en- English words
Field Reference
Required Fields
The word or phrase being defined.Validation:Invalid examples:
- Must be a string
- Cannot be empty
- Can include accents and special characters
Complete definition of the word.Validation:Invalid examples:
- Must be a string
- Cannot be empty
- Should be a clear, concise explanation
Array of usage examples showing the word in context.Validation:Invalid examples:
- Must be an array
- Must contain at least one string
- Each item must be a string
Grammatical category of the word. Must be one of the predefined values.Spanish values:Invalid examples:
"sustantivo"- Noun"verbo"- Verb"adjetivo"- Adjective"adverbio"- Adverb"expresión"- Expression"interjección"- Interjection"modismo"- Idiom
"noun""verb""adjective""adverb""expression""interjection""idiom"
Optional Fields
Geographic region where the word is commonly used.Validation:Invalid examples:
- Optional field
- Must be a string if provided
- Defaults to “Guatemala” if omitted
List of synonyms or similar words.Validation:Invalid examples:
- Optional field
- Must be an array of strings if provided
- Can be empty array
List of related words that might interest the reader.Validation:Invalid examples:
- Optional field
- Must be an array of strings if provided
- Can be empty array
Whether to feature this word on the homepage.Validation:Invalid examples:
- Optional field
- Must be a boolean if provided
- Defaults to
falseif omitted
Validation Errors
When validation fails, Astro provides detailed error messages to help you fix the issue.Common Error Examples
Missing Required Field
Invalid Category
Wrong Type
Empty Array
Type Safety
The Zod schema provides full TypeScript type safety:Validation at Build Time
Validation happens automatically during:-
Development mode (
npm run dev)- Validates when you save files
- Shows errors in the terminal
- Hot-reloads after fixing
-
Build time (
npm run build)- Validates all content before building
- Build fails if validation errors exist
- Ensures production site has valid data
All validation happens at build time, not runtime. This means your production site is guaranteed to have valid data.
Extending the Schema
To add new fields to the schema:- Edit
src/content/config.ts:3 - Add the field to the
wordsSchemaobject - Choose appropriate Zod validator
- Mark as optional with
.optional()if needed
Common Validation Patterns
Validate String Length
Validate Array Length
Add Custom Error Messages
Validate URLs
Transform Data
Testing Validation
To test if your word file is valid:-
Run the development server:
- Check the terminal for validation errors
-
Or run a build:
Related Resources
- Adding Words - How to create valid word files
- Content Collections - Querying validated data
- Zod Documentation - Learn more about Zod schemas
- Astro Content Collections - Official Astro docs