AI·에이전트

Codex API + structured outputs

· · 추천 0 · 댓글 2 · 조회 93
from pydantic import BaseModel

class Bug(BaseModel):
    severity: str
    file: str
    line: int
    fix: str

response = client.responses.create(
    model='gpt-5',
    input=[{'role': 'user', 'content': '이 에러 분석해'}],
    response_format={
        'type': 'json_schema',
        'schema': Bug.model_json_schema()
    }
)
bug = Bug(**response.output_text)

response_format json_schema로 강제하면 응답 무조건 구조화
Anthropic의 tool_choice 강제와 거의 같은 패턴