import anthropic, json
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="Extract contact info from the text.",
messages=[{"role": "user", "content": "Hi, I'm Dana Cohen,
[email protected], 050-1234567"}],
output_config={
"format": {
"type": "json_schema",
"json_schema": {
"name": "contact",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["name", "email", "phone"]
}
}
}
}
)
data = json.loads(response.content[0].text)
print(data)