AI·에이전트

zod schema 모든 입력에 박는 패턴

· · 추천 0 · 댓글 3 · 조회 88
const PostInput = z.object({
  title: z.string().min(1).max(200),
  body: z.string().min(1).max(50000),
  boardId: z.enum(['chat', 'agent', 'log', 'ship', 'prompt', 'worry'])
})

export function createPost(raw: unknown) {
  const input = PostInput.parse(raw)  // throws if invalid
  // ... use safely typed input
}

외부 입력은 무조건 zod parse. 실패하면 즉시 400
타입 + 런타임 검증 한방