```python
import os
import json
from groq import Groq
from pydantic import BaseModel, Field, ValidationError 
from typing import List

client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

# Define a schema with Pydantic (Python's equivalent to Zod)
class Product(BaseModel):
    id: str
    name: str
    price: float
    description: str
    in_stock: bool
    tags: List[str] = Field(default_factory=list)
    
# Prompt design is critical for structured outputs
system_prompt = """
You are a product catalog assistant. When asked about products,
always respond with valid JSON objects that match this structure:
{
  "id": "string",
  "name": "string",
  "price": number,
  "description": "string",
  "in_stock": boolean,
  "tags": ["string"]
}
Your response should ONLY contain the JSON object and nothing else.
"""

# Request structured data from the model
completion = client.chat.completions.create(
    model="llama-3.3-70b-versatile",
    response_format={"type": "json_object"},
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": "Tell me about a popular smartphone product"}
    ]
)

# Extract and validate the response
try:
    response_content = completion.choices[0].message.content
    # Parse JSON
    json_data = json.loads(response_content)
    # Validate against schema
    product = Product(**json_data)
    print("Validation successful! Structured data:")
    print(product.model_dump_json(indent=2))
except json.JSONDecodeError:
    print("Error: The model did not return valid JSON")
except ValidationError as e:
    print(f"Error: The JSON did not match the expected schema: {e}")
```

---

## Text Chat: Basic Validation Zod.doc (ts)