Extracteur de livres / ISBN
Les bibliothèques, les librairies et les vendeurs de livres d’occasion font tous face à la même corvée : transformer des notices de catalogue désordonnées en fiches structurées et propres. Collez une notice de catalogue — un texte de quatrième de couverture, une fiche d’éditeur ou une étiquette d’étagère numérisée — et récupérez le titre, l’auteur et l’ISBN, prêts à être versés dans une base de données ou un tableur d’inventaire. Le plus difficile, c’est l’ISBN lui-même. Il peut arriver avec ou sans son préfixe littéral (« ISBN », « ISBN-10 » ou « ISBN-13 »), avec des traits d’union, des espaces, ou sans rien du tout ; un ISBN-10 peut même se terminer par la lettre X, qui est un chiffre de contrôle valide, et non une faute de frappe. Les différentes éditions d’un même livre partagent un titre et un auteur, mais jamais un ISBN : le numéro est donc la seule clé fiable. Ce prompt refuse de deviner : si l’un des trois champs est absent de la notice, il ne produit aucune sortie plutôt que d’en inventer une.
Prompt système
You are a precise book extraction engine. Read the provided library catalog entry and return ONLY a valid JSON object matching the schema below. Do not add explanations, markdown, or extra fields. Every field is required: title, author, and isbn. Extract the best value printed in the entry and never invent a value that is not printed. Never use null or an empty string for a required field. The isbn must be the full ISBN-10 or ISBN-13 exactly as printed, keeping its hyphens or spaces; it may start with the literal prefix "ISBN", "ISBN-10", or "ISBN-13" followed by a space or a colon. If any required field (title, author, or isbn) cannot be found in the entry, do not produce any output.
Schéma JSON brut
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"author": {
"minLength": 1,
"type": "string"
},
"isbn": {
"minLength": 1,
"pattern": "^(?:ISBN(?:-1[03])?:?\\s*)?(?:(?:\\d[-\\s]?){9}[\\dX]|(?:\\d[-\\s]?){12}\\d)$",
"type": "string"
},
"title": {
"minLength": 1,
"type": "string"
}
},
"required": [
"title",
"author",
"isbn"
],
"title": "BookIsbn",
"type": "object"
}
Zod (TypeScript)
import { z } from "zod";
export const BookIsbnSchema = z
.object({
title: z.string().min(1),
author: z.string().min(1),
isbn: z
.string()
.min(1)
.regex(
/^(?:ISBN(?:-1[03])?:?\s*)?(?:(?:\d[-\s]?){9}[\dX]|(?:\d[-\s]?){12}\d)$/
),
})
.strict();
Pydantic v2 (Python)
from pydantic import BaseModel, Field, field_validator
class BookIsbn(BaseModel):
title: str = Field(..., min_length=1)
author: str = Field(..., min_length=1)
isbn: str = Field(
...,
min_length=1,
pattern=r"^(?:ISBN(?:-1[03])?:?\s*)?(?:(?:\d[-\s]?){9}[\dX]|(?:\d[-\s]?){12}\d)$",
)
@field_validator("title", "author", "isbn", mode="before")
@classmethod
def _strip_strings(cls, v):
if not isinstance(v, str):
return v
return v.strip()