# Model Primitive Sentiment - Classification Examples

> A minimal Model primitive example using a mock backend. Demonstrates: - Stateless prediction via the Model primitive - Input/output schemas on the model itself - Deterministic specs that run in CI without API keys

Canonical: https://tactus.anth.us/examples/classification/model-primitive-sentiment/

::band{columns="document-hero wide"}

[Examples](/examples/) / [Classification](/examples/classification/) / Model Primitive Sentiment

# Model Primitive Sentiment

- Has Specs

A minimal Model primitive example using a mock backend. Demonstrates: - Stateless prediction via the Model primitive - Input/output schemas on the model itself - Deterministic specs that run in CI without API keys

::band{tone="muted" columns="example"}

## Source Code

```lua
-- Model Primitive: Mocked Sentiment Classifier
--
-- Use a Model primitive when you want stateless, repeatable predictions.
-- This example uses a mock backend so it runs in CI without API keys.

Model "sentiment_mock" {
  type = "mock",
  value = {label = "positive", confidence = 0.93},
  input = {text = "string"},
  output = {label = "string", confidence = "float"}
}

Procedure {
  input = {
    text = field.string{required = true, description = "Text to classify"}
  },
  output = {
    label = field.string{required = true, description = "Sentiment label"},
    confidence = field.number{required = true, description = "Confidence score"}
  },
  function(input)
    local classifier = Model("sentiment_mock")
    local result = classifier({text = input.text})
    local output = result.output or result

    return {label = output.label, confidence = output.confidence}
  end
}

Specification([[
Feature: Model primitive (mocked sentiment)

  Scenario: Returns the mocked label and confidence
    Given the procedure has started
    And the input text is "This product is wonderful."
    When the procedure runs
    Then the procedure should complete successfully
    And the output label should be "positive"
    And the output confidence should be 0.93
]])
```

## Quick Start

Run the example:

```bash
tactus run 02-classification/03-model-primitive-sentiment.tac
```

Test with mocks:

```bash
tactus test 02-classification/03-model-primitive-sentiment.tac --mock
```

[View source on GitHub →](https://github.com/AnthusAI/Tactus-examples/blob/main/02-classification/03-model-primitive-sentiment.tac)

::band{columns="neighbors"}

- [*← Previous Example* **Composite Fuzzy Then Llm**](/examples/classification/composite-fuzzy-then-llm/)
- [*Next Example →* **Model Train Imdb Naive Bayes**](/examples/classification/model-train-imdb-naive-bayes/)

::band{columns="cta"}

## Explore more examples

Learn Tactus through practical, runnable examples organized by topic.

::button{href="/examples/" label="View All Examples" size="lg"}
