Extracteur d’événements de calendrier
Les invitations aux réunions, les messages de discussion et les courriels transférés noient sans cesse les détails d’un événement dans la prose : « Retrouvons-nous mardi à 14 h dans la salle B avec Ana et Marc. » Ce prompt transforme cette prose en événement de calendrier structuré — titre, heures de début et de fin en ISO 8601, lieu, courriels des participants et indicateur de journée entière — prêt à alimenter une API de calendrier ou un agent de planification. Il gère les pièges courants : les heures de fin et les lieux sont souvent absents, et le schéma le dit explicitement avec null au lieu d’inventer un créneau d’une heure ou une salle par défaut. Les dates relatives comme « demain » ou « vendredi prochain » doivent être résolues par rapport à la date du jour avant d’appeler le modèle, car le modèle n’a pas d’horloge. Et un événement d’une journée entière n’est pas la même chose qu’un événement de minuit à minuit : l’indicateur is_all_day préserve cette distinction au lieu de simuler une plage horaire.
Prompt système
You are a calendar event extractor. Read the text below and return a single JSON object that matches the provided schema exactly. Extract the event title and its start date and time as an ISO 8601 datetime, for example 2026-11-20T14:30:00. If an end date and time is stated, extract it the same way; if no end is stated, set end_datetime to null. If a location is stated, extract it; if no location is stated, set location to null. List every attendee email address found in the text in attendees; use an empty array when no attendee is mentioned. Set is_all_day to true only when the event spans a whole day with no specific start time, otherwise false. Rules: - Output only the JSON object, with no extra text, no markdown fences, and no commentary. - Extract the best value present in the text. Do not invent a title, a time, a location, or an attendee that is not in the text. - If the title or the start date and time cannot be determined from the text, do not produce any output. - The title must be non-empty. Datetimes must be valid ISO 8601. Every attendee must be a valid email address.
Schéma JSON brut
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CalendarEvent",
"type": "object",
"additionalProperties": false,
"required": ["title", "start_datetime", "end_datetime", "location", "attendees", "is_all_day"],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"start_datetime": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?$"
},
"end_datetime": {
"type": ["string", "null"],
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?$"
},
"location": {
"type": ["string", "null"],
"minLength": 1
},
"attendees": {
"type": "array",
"items": {
"type": "string",
"pattern": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
}
},
"is_all_day": {
"type": "boolean"
}
}
}
Zod (TypeScript)
import { z } from "zod";
const isoDatetime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;
const email = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
export const CalendarEventSchema = z.strictObject({
title: z.string().min(1),
start_datetime: z.string().regex(isoDatetime),
end_datetime: z.string().regex(isoDatetime).nullable(),
location: z.string().min(1).nullable(),
attendees: z.array(z.string().regex(email)),
is_all_day: z.boolean(),
});
export type CalendarEvent = z.infer<typeof CalendarEventSchema>;
Pydantic v2 (Python)
from typing import Annotated
from pydantic import BaseModel, ConfigDict, Field, field_validator
class CalendarEvent(BaseModel):
model_config = ConfigDict(extra="forbid")
title: str = Field(..., min_length=1)
start_datetime: str = Field(..., pattern=r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$")
end_datetime: str | None = Field(..., pattern=r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$")
location: str | None = Field(..., min_length=1)
attendees: list[Annotated[str, Field(pattern=r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$")]]
is_all_day: bool
@field_validator("title", "start_datetime", "end_datetime", "location", mode="before")
@classmethod
def _strip_text(cls, v):
if not isinstance(v, str):
return v
return v.strip()