본문 바로가기
C.W.K.
Stream
Lesson 02 of 07 · published

Strict Mode — schema-enforced 호출

~22 min · strict, schema-validation

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

strict=True 는 운영 환경에서 기본으로 삼을 만해. strict mode 가 없으면 모델이 schema 와 거의 맞지만 한 필드가 다른 arguments 를 반환할 수 있어. strict mode 에서는 API 가 맞지 않는 시도를 거부하고 schema 에 맞는 출력을 다시 만들게 해 방어적인 parsing 부담을 줄여.

additionalProperties: false 가 필요해

strict mode 는 모든 object schema 에 additionalProperties: false 를 요구해. 하나라도 빠뜨리면 모델 호출 전에 API 가 tool 정의 자체를 거부해.

실패 사례를 직접 비교해봐

enum field 가 있는 tool 에 strict mode 없이 허용되지 않은 값을 유도하는 prompt 를 보내봐. 이어서 strict mode 를 켜고 같은 prompt 를 보내 API 가 잘못된 호출을 application 에 도달하기 전에 막는지 확인해.

조금의 지연으로 안정성을 사

첫 출력이 schema 에 맞지 않으면 내부 재생성이 일어나 지연과 비용이 조금 늘 수 있어. 그 대신 잘못된 JSON 을 application 에서 복구하는 코드와 장애를 크게 줄일 수 있어.

Code

Tool with strict=True·python
{
    "type": "function",
    "name": "create_event",
    "description": "Create a calendar event",
    "parameters": {
        "type": "object",
        "properties": {
            "title": {"type": "string"},
            "date": {"type": "string", "description": "ISO 8601 date"},
            "description": {"type": ["string", "null"]},  # optional via null union
        },
        "required": ["title", "date", "description"],     # ALL fields required
        "additionalProperties": False,                     # mandatory for strict
    },
    "strict": True,
}

External links

Exercise

enum field 가 있는 tool 에 strict mode 없이 잘못된 값을 유도하는 prompt 를 보내. 이어서 strict=True 로 바꾸고 API 가 잘못된 호출을 거부하는지 비교해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.