jevrecipes

Recipe catalog / topic-shift

Detect a topic shift

topic-shift is a Jev recipe from the jev-recipes TypeScript package. Does message stay with currentTopic, introduce a different topic, or contain both? Use it when you need to detect whether a message moves away from the current topic.

Last updated .

Explore this recipe interactively · Source and implementation guide · Markdown version

How do I use topic-shift in TypeScript?

Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.

import { topicShift } from 'jev-recipes/topic-shift';

const result = await topicShift({
  "currentTopic": "Resetting a password.",
  "message": "Also, where can I download my invoices?"
});
console.log(result);

What input does topic-shift take?

FieldTypeNeeded
currentTopicstringRequired
messagestringRequired
contextstringOptional
minConfidencenumberOptional
Full input and result schemas
{
  "input": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "currentTopic": {
        "type": "string"
      },
      "message": {
        "type": "string"
      },
      "context": {
        "type": "string"
      },
      "minConfidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    },
    "required": [
      "currentTopic",
      "message"
    ]
  },
  "result": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "model": {
        "type": "string"
      },
      "usage": {
        "type": "object",
        "properties": {
          "input_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "output_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "input_tokens",
          "output_tokens"
        ],
        "additionalProperties": false
      },
      "status": {
        "type": "string",
        "enum": [
          "ready",
          "review"
        ]
      },
      "verdict": {
        "type": "string",
        "enum": [
          "same_topic",
          "new_topic",
          "mixed",
          "unclear"
        ]
      },
      "confidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "probabilities": {
        "type": "object",
        "propertyNames": {
          "type": "string",
          "enum": [
            "same_topic",
            "new_topic",
            "mixed",
            "unclear"
          ]
        },
        "additionalProperties": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "required": [
          "same_topic",
          "new_topic",
          "mixed",
          "unclear"
        ]
      }
    },
    "required": [
      "model",
      "usage",
      "status",
      "verdict",
      "confidence",
      "probabilities"
    ],
    "additionalProperties": false
  }
}

What does a topic-shift result look like?

This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo topic-shift.

{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "verdict": "new_topic",
  "confidence": 0.96,
  "probabilities": {
    "same_topic": 0,
    "new_topic": 1,
    "mixed": 0,
    "unclear": 0
  }
}

Input

See shared options and behavior for client configuration, validation, and errors.

Result

Verdict Meaning
same_topic The message remains within the current subject.
new_topic The message moves to a different subject.
mixed The message substantively addresses both the current and a new subject.
unclear The subject relationship cannot be resolved.

The result includes verdict, confidence, and all choice probabilities. unclear always requires review, even at high confidence. Other verdicts can be ready, including negative assessments.

Results include model and token usage. Decisions below minConfidence require review. Inspect the outcome as well as the status.

Reuse and calls

Uses the shared choice helper for the Jev call and response parsing. This folder owns its question, verdict criteria, and review policy. A live invocation makes one logical Jev request; SDK retries can add transport attempts.

Limits

Compares one message with a supplied topic. It does not generate topic labels or split conversation threads.

Example input

demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo topic-shift shows the result offline. The fixture is an illustration, not an accuracy measurement. npx jev-recipes describe topic-shift shows the input and result schemas.

How accurate is topic-shift?

Fixture only

No verified live accuracy measurement is available. Evaluate representative cases before using this decision in your workflow.

Use the evaluation guide to measure this decision on your own labeled cases.

What are the limits of topic-shift?