{}
StrictJSON
Classification

Sentiment des avis produits

Les vendeurs, les équipes de support et les chefs de produit se noient dans les avis clients : des centaines de notes en étoiles accompagnées d’une phrase ou deux, chacune cachant une plainte concrète ou un compliment sincère. Ce prompt lit un seul avis produit et renvoie un verdict structuré — un sentiment global, un score de 0 à 100, les forces et les faiblesses sous forme de courtes listes, un résumé en une phrase et une recommandation par oui ou par non. Les pièges sont bien réels : un avis cinq étoiles peut quand même mentionner un défaut, un avis furieux peut quand même louer l’emballage, et le sarcasme peut inverser le ton apparent. Le score est lié à la tranche de sentiment, pour qu’un avis « positif » ne puisse jamais obtenir 12 et qu’un avis « négatif » ne puisse jamais obtenir 95. Les aspects ne sont jamais inventés — si l’évaluateur n’a jamais mentionné l’autonomie de la batterie, elle reste hors des deux listes. Injectez les résultats dans un tableau de bord et les tendances sur des centaines d’avis deviennent visibles en quelques minutes.

Prompt système

You are a precise product review sentiment analyzer. Read the provided product review and return ONLY a valid JSON object matching the schema below. Do not add explanations, markdown, or extra fields. Every field is required and must never be null or an empty string: sentiment, score, positive_aspects, negative_aspects, summary, and recommends. Classify sentiment as "positive", "neutral", or "negative" based on the overall tone of the review. Score is an integer from 0 (very negative) to 100 (very positive) that matches the sentiment: 0-39 for negative, 40-60 for neutral, 61-100 for positive. List every concrete strength in positive_aspects and every concrete weakness in negative_aspects as short phrases; use an empty array when the review mentions none. Summary is a single sentence capturing the reviewer's overall verdict. Recommends is true only when the reviewer would recommend the product. Never invent aspects the review does not mention. If the text is not a product review, do not produce any output.

Schéma JSON brut

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "properties": {
    "negative_aspects": {
      "items": {
        "minLength": 1,
        "type": "string"
      },
      "type": "array"
    },
    "positive_aspects": {
      "items": {
        "minLength": 1,
        "type": "string"
      },
      "type": "array"
    },
    "recommends": {
      "type": "boolean"
    },
    "score": {
      "maximum": 100,
      "minimum": 0,
      "type": "integer"
    },
    "sentiment": {
      "enum": [
        "positive",
        "neutral",
        "negative"
      ],
      "type": "string"
    },
    "summary": {
      "minLength": 1,
      "type": "string"
    }
  },
  "required": [
    "sentiment",
    "score",
    "positive_aspects",
    "negative_aspects",
    "summary",
    "recommends"
  ],
  "title": "ProductReviewSentiment",
  "type": "object"
}

Zod (TypeScript)

import { z } from "zod";

export const ProductReviewSentimentSchema = z
  .object({
    sentiment: z.enum(["positive", "neutral", "negative"]),
    score: z.number().int().min(0).max(100),
    positive_aspects: z.array(z.string().min(1)),
    negative_aspects: z.array(z.string().min(1)),
    summary: z.string().min(1),
    recommends: z.boolean(),
  })
  .strict();

Pydantic v2 (Python)

from typing import Annotated, Literal

from pydantic import BaseModel, Field, field_validator


class ProductReviewSentiment(BaseModel):
    sentiment: Literal["positive", "neutral", "negative"]
    score: int = Field(..., ge=0, le=100)
    positive_aspects: list[Annotated[str, Field(min_length=1)]] = Field(...)
    negative_aspects: list[Annotated[str, Field(min_length=1)]] = Field(...)
    summary: str = Field(..., min_length=1)
    recommends: bool

    @field_validator("summary", mode="before")
    @classmethod
    def _strip_summary(cls, v):
        if not isinstance(v, str):
            return v
        return v.strip()

    @field_validator("positive_aspects", "negative_aspects", mode="before")
    @classmethod
    def _strip_aspects(cls, v):
        if not isinstance(v, list):
            return v
        return [item.strip() if isinstance(item, str) else item for item in v]

Essayer dans l’outil StrictJSON →