Open
Description
Description
I am getting this typevalidation error despite my zod schema looking correct. Am I doing something wrong?
Error
_TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {"analyses":[[{"start":9,"end":13,"id":"sweepingCorner","titles":["Curved Delight","Bendtastic","Corner Carnival","Twisty Fun","Curved Whimsy","Bend Bliss","Twisted Joy","Corner Charm","Curved Magic","Bend Beauty"]}]]}.
Error message: [
{
"code": "invalid_type",
"expected": "object",
"received": "array",
"path": [
"analyses",
0
],
"message": "Expected object, received array"
}
]
schema:
export const analyzeSegmentResponseSchema = z.object({
analyses: z.array(
z.object({
start: z.number().int(),
end: z.number().int(),
id: z.string(),
titles: z.array(z.string()),
}),
),
})
prompts:
export const getSegmentAnalysisSysPrompt = () => `
System:
**Role Description**:
This system is designed to analyze segments of the input image of a racetrack being drawn point by point.
Focus carefully on the points on the path and recognize the segment ranges when given.
Be aware of the input distance
The system uses the following rules to help it identify the track features:
Chicanes typically have more than 2 corners medium tight corners and should include at least 5 points.
Hairpins are 1 corner and must be acute and at most 30 degrees, should have a short radius, and maximum of 3 points.
Straightaways should not have any corners can range accross many points.
Sweepers are long radius corners and can have many points.
S-Curves should have at least 2 wide corners and should have at least 5 points.
**Data:**
<trackFeaturesDictionary>
${Object.keys(trackFeatures)
.map(
(key) => `
<id>${key}</id>
`,
)
.join('\n')}
</trackFeaturesDictionary>
`
export const getSegmentAnalysisPrompt = (start: number, end: number, distance: number) => `
**Input Parameters:**
**Start Point:**
<startPoint>${start}</startPoint>
**End Point:**
<endPoint>${end}</endPoint>
**Distance of Segment:**
<segmentDistance>${distance}km</segmentDistance>
Think before you create this anaylsis in.
1. Choose a range within the <startPoint> and <endPoint> that can be described by the <id> from the <trackFeaturesDictionary>
Consider the <segmentDistance> of the range in choosing what type of feature it is.
The middle point of that range must be the most important point in the segment.
It must not be the entirity of the input range
Start must always be less than end.
place values into <id>, <start> and <end> tags
2. generate a list of 5-10 titles for the segment.
Try to be irrelevant and fun with the titles.
place the titles into <titles> tags
Review the data and make sure it adheres to the instructions. If it does not start over.
`
createObject call
export async function analyzeTrackSegment({ startIndex, endIndex, image, distance }: AnalyzeTrackSegmentInput) {
const imagePart: ImagePart = {
type: 'image',
image: image.imageData,
mimeType: image.contentType,
}
const system = getSegmentAnalysisSysPrompt()
const text = getSegmentAnalysisPrompt(startIndex, endIndex, distance)
const messages: CoreMessage[] = [
{
role: 'user',
content: [
imagePart,
{
type: 'text',
text,
},
],
},
]
const now = Date.now()
const result = await generateObject({
model: bedrock(AWS_REASONING_MODEL_HIGH_ID as string),
schema: analyzeSegmentResponseSchema,
system,
messages,
temperature: defaultTemperature,
maxTokens: defaultMaxTokens,
})
console.log('Receive Text', Date.now() - now)
return result.object
}
AI SDK Version
"@ai-sdk/amazon-bedrock": "^2.2.9",
"ai": "^4.3.15",
"zod": "^3.23.8",