Function calling ignoring JSON Schema field attributes

Hi, I’m using function calling to extract data from a string. However, JSON schema field attributes, like “examples”, “pattern”, “maxLength” seems to be ignored.

Let’s say I have,

import datetime
from pydantic import BaseModel, Field

class Document(BaseModel):
    last_name: str
    first_name: str
    sex: Literal["M", "F", "X"]
    nationality: str
    document: str = Field(
        ...,
        pattern=r"\d{1,2}\.\d{3}\.\d{3}",
        examples=["12.345.678"],
        max_length=10,
    )
    birth_date: datetime.date = Field(
        ...,
        description="Date format: DD/MM/YYYY",
    )

input_text = """
Last name
DOE
First Name
JANE
Sex
F
Nationality
USA
Date of birth
02 APR 1982
Document 1233.231.12331
"""

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "Only use the functions you have been provided with."},
        {"role": "user", "content": input_text},
    ],
    functions=[
        {
            "name": "extract_data",
            "description": "Extract data from text. Date fields must match DD/MM/YYYY format.",
            "parameters": Document.model_json_schema(),
        }
    ],
)
print(response["choices"][0]["message"]["function_call"]["arguments"])

Prints,

{'last_name': 'DOE',
 'first_name': 'JANE',
 'sex': 'F',
 'nationality': 'USA',
 'document': '1233.231.12331',
 'birth_date': '02 APR 1982'}

The JSON schema generated from Pydantic is:

{'properties': {'last_name': {'title': 'Last name', 'type': 'string'},
  'first_name': {'title': 'First name', 'type': 'string'},
  'sex': {'enum': ['M', 'F', 'X'], 'title': 'Sex', 'type': 'string'},
  'nationality': {'title': 'Nationality', 'type': 'string'},
  'document': {'examples': ['12.345.678'],
   'maxLength': 10,
   'pattern': '\\d{1,2}\\.\\d{3}\\.\\d{3}',
   'title': 'Document',
   'type': 'string'},
  'birth_date': {'description': 'Date format: DD/MM/YYYY',
   'format': 'date',
   'title': 'Birth date',
   'type': 'string'}},
 'required': ['last_name',
  'first_name',
  'sex',
  'nationality',
  'document',
  'birth_date'],
 'title': 'Document',
 'type': 'object'}

However, based on the schema, I would expect this to came out,

{'last_name': 'DOE',
 'first_name': 'JANE',
 'sex': 'F',
 'nationality': 'USA',
 'document': '33.231.123',
 'birth_date': '02/04/1982'}

I know that there are some parsing and typos in my input text, as that’s a OCR output with some errors, but a simpler prompt like

Parse this text an convert it to JSON, date fields should have DD/MM/YYYY, and id number should be XX.XXX.XXX"

works better than the function! why?

Does OpenAI function calling feature uses field’s attrs like examples, pattern, description, maxLength to build its question prompt? I’d prefer using function calling with a JSON schema, but it’s been frustrating.

I would expect to be able to instruct the model how to extract the value with field descriptions.