# Contracts

> Every app declares what it receives and what it returns as two JSON Schema files. The input contract shapes sdk.input; the output contract is the payload of sdk.submitOutput that tasks, workflows and other apps rely on.

Source: https://docs.sommatic.ai/en/apps/contracts/ (updated 2026-11-26)

A contract turns an app into a dependable step. Whoever opens the app knows what to send; whoever consumes its result
knows what comes back. Contracts live in the `contracts/` folder of every app:

```text
contracts/
├── input.schema.json     # what the app receives
└── output.schema.json    # what the app returns
```

## Input contract

`contracts/input.schema.json` describes the payload the app opens with. At runtime it is `sdk.input`.

```json
{
  "type": "object",
  "properties": {
    "title": { "type": "string", "description": "Title shown in the header" },
    "description": { "type": "string", "description": "What needs to be reviewed" },
    "priority": {
      "type": "string",
      "enum": ["low", "medium", "high", "critical"],
      "description": "Priority level"
    },
    "data": { "type": "object", "description": "Payload to review" }
  },
  "required": ["title"]
}
```

```jsx
function Review({ sdk }) {
  const { title, description } = sdk?.input || {};

  if (!title) {
    return <p>No data to review.</p>;
  }

  return (
    <section>
      <h2>{title}</h2>
      <p>{description}</p>
    </section>
  );
}
```

## Output contract

`contracts/output.schema.json` describes the payload the app returns with `sdk.submitOutput(payload)`.

```json
{
  "type": "object",
  "properties": {
    "decision": {
      "type": "string",
      "enum": ["approved", "rejected", "escalated"],
      "description": "The reviewer's decision"
    },
    "notes": { "type": "string", "description": "Justification" },
    "reviewed_at": { "type": "string", "format": "date-time", "description": "When it was reviewed" }
  },
  "required": ["decision"]
}
```

```javascript
sdk.submitOutput({ decision: 'approved', notes, reviewed_at: new Date().toISOString() });
```

When an app opened from a task submits its output in the portal, the output becomes the task's `outputs`: a `decision`
of `rejected` rejects the task, any other output completes it. Align the output contract with the task's
`required_output` so the completion passes [validation](https://docs.sommatic.ai/en/human-in-the-loop/task-lifecycle.md).

> **Warning: The app enforces its own output**
>
> The session stores the output as it is sent. Check the required fields of your output contract in the app before you
> call `submitOutput`.

## Schema keywords

Contracts use JSON Schema (draft-07 compatible):

| Keyword                                        | Use                                               |
| ---------------------------------------------- | ------------------------------------------------- |
| `type`, `properties`, `required`, `items`      | Structure.                                        |
| `enum`                                         | Fixed choices: decisions, statuses, priorities.   |
| `description`                                  | What a field means, for whoever connects the app. |
| `format`                                       | `date-time`, `email`, `uri`.                      |
| `default`                                      | Default value.                                    |
| `minLength`, `maxLength`, `minimum`, `maximum` | Limits.                                           |

## Draft, submit or cancel

| Call                        | Payload must match the output contract | Session                                   |
| --------------------------- | -------------------------------------- | ----------------------------------------- |
| `sdk.saveDraft(payload)`    | No                                     | Stays open; call it as often as you need. |
| `sdk.submitOutput(payload)` | Yes                                    | Completed. Call it once.                  |
| `sdk.cancel(reason)`        | No output                              | Cancelled.                                |

## Apps that need input

The manifest says whether the app can open without input:

| Manifest                                                           | Behavior                                                   |
| ------------------------------------------------------------------ | ---------------------------------------------------------- |
| `"entry_behavior": "home"`, `"requires_context": false`            | Opens to its home view; input is optional.                 |
| `"entry_behavior": "context-required"`, `"requires_context": true` | Needs an input. The launcher does not show it without one. |

An app that takes no input or returns no output still ships both files, with an empty schema:

```json
{ "type": "object", "properties": {}, "required": [] }
```

## Good practice

1. Always ship both contracts, even empty: they document the app.
2. Mark required fields explicitly.
3. Describe every property.
4. Use `enum` for fixed choices, so the output can drive routing.
5. Keep the output small: only what consumers need.
6. When you change a contract, keep it compatible with the workflows and tasks that already use it.

## Next steps

- [Apps in workflows](https://docs.sommatic.ai/en/apps/workflow-bridge.md): Where the output goes today.
- [Human in the loop](https://docs.sommatic.ai/en/human-in-the-loop.md): Tasks and their required outputs.
