"매 raw bytes → structured value". 매 parsing 의 input string/bytes 의 grammar 의 따라 typed tree 의 변환 — 매 modern stack 의 schema-first (Pydantic v2, Zod, Protobuf) + zero-copy (Arrow, simdjson) 의 dominant.
import{z}from"zod";constUser=z.object({id: z.number().int().positive(),email: z.string().email(),tags: z.array(z.string()).max(10).default([]),});constuser=User.parse(JSON.parse(raw));// throws on invalid
typeUser=z.infer<typeofUser>;// static type
Protobuf (binary, schema)
importuser_pb2user=user_pb2.User()user.ParseFromString(raw_bytes)# zero-allocation in C++
Apache Arrow (columnar, zero-copy)
importpyarrow.csvaspvtable=pv.read_csv("data.csv")# multi-threaded, zero-copy to pandasdf=table.to_pandas(zero_copy_only=True)
언제: structured output enforcement (JSON schema → Pydantic), tool call argument 의 parse.
언제 X: free-form natural language — 매 parsing 의 wrong tool, embedding/LLM 의 use.
❌ 안티패턴
Regex 의 HTML/JSON parse: 매 grammar 의 non-regular, 의 use proper parser.
Stringly-typed: 매 dict[str, Any] 의 propagate, 의 typed model 의 boundary 의 parse.
Validate-only: 매 raw dict 의 keep + ad-hoc check, 의 parse 의 structure 의 commit.
Eager full-load: 매 GB JSON 의 json.load, 의 streaming 의 use.