# Schema

Canonical URL: https://developers.iagenify.com/de/sdk/ref/models/schema/
Language: de

`api.models.create({ schema })`

Geben Sie der Sitzung einen JSON Schema und es beantwortet Objekte statt Prosa. Dies ist, was ein Modell in etwas verwandelt, was der Rest Ihres Codes nennen kann.

Status: set at creation · changes the default output · JSON Schema

Ohne Schema erhält man Text, und wer es verbraucht, muss Englisch lesen. Mit einem erhält man einen Wert – und der Unterschied ist nicht einfach, es ist, ob die nächste Funktion überhaupt geschrieben werden kann.

## Einstellen {#setting}

```javascript
const extractor = await api.models.create({
  model: "gemini-3.5-flash",
  settings: { temperature: 0 },
  schema: {
    type: "object",
    properties: {
      supplier: { type: "string" },
      total:    { type: "number", description: "Amount including tax" },
      currency: { type: "string", description: "ISO 4217, e.g. EUR" },
      dueDate:  { type: "string", description: "ISO 8601 date" },
      lines: {
        type: "array",
        items: {
          type: "object",
          properties: { label: { type: "string" }, amount: { type: "number" } },
          required: ["label", "amount"],
        },
      },
    },
    required: ["supplier", "total", "currency"],
  },
});

const { outputs } = await extractor.generate({
  inputs: [{ type: "text", content: "Extract this invoice." },
           { type: "file", url: "https://example.com/invoice.pdf" }],
});

outputs[0].content;   // an object, not a string
```

## Es ändert, was die Sitzung standardmäßig beantwortet {#default}

Eine Sitzung mit einem Schema antwortet JSON es sei denn, ein Anruf verlangt etwas anderes; eine Sitzung ohne einen Antworttext. Sie können pro Anruf überschreiben.

```javascript
await extractor.generate({ inputs });                          // JSON — the schema
await extractor.generate({ inputs, outputs: [{ type: "text" }] }); // prose, this once
```

## Die Beschreibungen sind keine Dokumentation {#descriptions}

Sie werden vom Modell gelesen, und sie sind, wo Mehrdeutigkeit geregelt wird. `total` allein lädt eine Vermutung über Steuern; `total` mit « Betrag einschließlich Steuern » nicht.

| Feld | Ohne Beschreibung | Mit einem |
| --- | --- | --- |
| Insgesamt | Vor oder nach Steuern? Jeder Anruf kann abweichen. | „Einschl. Steuern" — abgegolten. |
| Datum | Jedes Format, das das Modell mag. | « ISO 8601 » — leserlich. |
| Status | Freier Text, unbeschränkt. | Enum verwenden: Der Satz ist der Vertrag. |

```javascript
{
  status: { type: "string", enum: ["paid", "pending", "overdue"] },
  confidence: { type: "number", description: "0 to 1. Below 0.5 means the document was unclear." }
}
```

> **Bitten Sie um die Unsicherheit, nicht folgern Sie es**
>
> Ein Modell füllt jedes Feld, das es gegeben wird. Eine Vertrauenszahl oder ein Nullfeld mit „ null, wenn das Dokument nicht sagt", ist, wie man eine Lesung von einer Vermutung erzählt – und es kostet ein paar Zeichen.

## Es trotzdem bestätigen {#validate}

Die Form wird dringend verlangt, und Sie sollten sie noch überprüfen, bevor Sie darauf reagieren — genauso wie Sie eine Antwort von einem Dienst, den Sie nicht kontrollieren, bestätigen würden.

```javascript
const invoice = outputs[0].content;

if (typeof invoice?.total !== "number" || !invoice.currency) {
  throw new Error("the extraction did not come back in the expected shape");
}
```

## Eine Form für einen Anruf {#per-call}

Sie müssen keine Sitzung öffnen, um eine Form zu erhalten. Fragen Sie nach ihr auf dem Anruf — nützlich, wenn jede Frage eine andere will.

```javascript
await assistant.generate({
  inputs: [{ type: "text", content: "Three risks of shipping on a Friday." }],
  outputs: [{ type: "json", schema: {
    type: "object",
    properties: { risks: { type: "array", items: { type: "string" } } },
    required: ["risks"],
  } }],
});
```

## Behalten Sie es die Größe der Antwort {#size}

Das Schema wird mit jedem Anruf gesendet, so dass ein großes ein Standing-Kosten pro Antwort ist. Fragen Sie nach den Feldern, die Sie verwenden werden; ein Schema mit dreißig optionalen Feldern, die Sie nie lesen, wird für dreißig Mal über bezahlt.

- [Ausgabetypen](/de/sdk/concepts/outputs): Alles, was ein Anruf zurückgeben kann, und wie binär geschrieben wird.
- [generate()](/de/sdk/ref/assistant-session/generate): Fragen, und was zurückkommt.

```python
extractor = api.models.create(
    model="gemini-3.5-flash",
    settings={"temperature": 0},
    schema={
        "type": "object",
        "properties": {
            "supplier": {"type": "string"},
            "total": {"type": "number", "description": "Amount including tax"},
            "currency": {"type": "string", "description": "ISO 4217, e.g. EUR"},
            "dueDate": {"type": "string", "description": "ISO 8601 date"},
            "lines": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {"label": {"type": "string"}, "amount": {"type": "number"}},
                    "required": ["label", "amount"],
                },
            },
        },
        "required": ["supplier", "total", "currency"],
    },
)

outputs = extractor.generate(inputs=[
    {"type": "text", "content": "Extract this invoice."},
    {"type": "file", "url": "https://example.com/invoice.pdf"},
])["outputs"]

outputs[0]["content"]   # an object, not a string
```

```python
extractor.generate(inputs=inputs)                              # JSON — the schema
extractor.generate(inputs=inputs, outputs=[{"type": "text"}])  # prose, this once
```

```python
{
    "status": {"type": "string", "enum": ["paid", "pending", "overdue"]},
    "confidence": {"type": "number", "description": "0 to 1. Below 0.5 means the document was unclear."},
}
```

```python
invoice = outputs[0]["content"]

if not isinstance(invoice, dict) or not isinstance(invoice.get("total"), (int, float)) or not invoice.get("currency"):
    raise ValueError("the extraction did not come back in the expected shape")
```

```python
assistant.generate(
    inputs=[{"type": "text", "content": "Three risks of shipping on a Friday."}],
    outputs=[{"type": "json", "schema": {
        "type": "object",
        "properties": {"risks": {"type": "array", "items": {"type": "string"}}},
        "required": ["risks"],
    }}],
)
```
