# Quality Scoring

The PizzaStack API tracks quality through the entire pipeline. The final `overall_score` in the `/pizza/bake` response reflects whether all preparation steps were executed correctly.

## Score Ranges

| Score Range | Meaning                                 |
| ----------- | --------------------------------------- |
| 0.90 – 0.98 | All preparation steps were correct      |
| 0.35 – 0.50 | One or more preparation errors occurred |

## What Degrades Quality

Quality degrades when ingredients are passed to a cooking step in the wrong state. Currently, the main source of degradation is:

**Passing a raw tomato ID to `/cook/simmer`**

The `/cook/simmer` endpoint accepts raw tomato IDs without returning an error. Instead, it returns `sauce_quality: "degraded"` with `degradation_reason: "raw_ingredient"`. This is a silent failure — HTTP status is still 200.

To avoid this, always slice tomatoes before simmering:

1. `/tomato/acquire` → get a raw tomato ID
2. `/tomato/slice` → get a sliced ID
3. `/cook/simmer` → pass the sliced ID

## How Degradation Propagates

Degradation is sticky — once any step produces a degraded result, all downstream steps are also degraded:

```
raw tomato → /cook/simmer → sauce_quality: "degraded"
                                    ↓
                           /pizza/assemble → assembly_quality: "degraded"
                                    ↓
                            /pizza/bake → overall_score: 0.35–0.50
```

Compare with the correct pipeline:

```
raw tomato → /tomato/slice → /cook/simmer → sauce_quality: "optimal"
                                                    ↓
                                           /pizza/assemble → assembly_quality: "optimal"
                                                    ↓
                                            /pizza/bake → overall_score: 0.90–0.98
```

## Sub-Scores

The `/pizza/bake` response includes several sub-scores in `quality_metrics`:

| Metric                 | Description                                  |
| ---------------------- | -------------------------------------------- |
| `overall_score`        | Final composite quality score (0.0–1.0)      |
| `crust_crispness`      | Quality of the crust                         |
| `cheese_melt`          | Quality of cheese melting                    |
| `topping_distribution` | Evenness of topping placement                |
| `sauce_integration`    | How well the sauce integrates with the pizza |

All sub-scores are affected by upstream degradation. A degraded sauce will produce low scores across all metrics, not just `sauce_integration`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tomatopy.pizza/docs/developer-documentation/quality-scoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
