Semantic anomaly detection with large language models

Amine Elhafsi, Rohan Sinha, Christopher Agia, Edward Schmerling, Issa A. D. Nesnas, Marco Pavone

Abstract

Traditional robotic Out-of-Distribution (OOD) detection focuses on low-level visual discrepancies, often failing to identify "semantic anomalies"—scenarios where objects are visually familiar but contextually inappropriate. This paper introduces a novel framework that leverages the broad world knowledge and reasoning capabilities of Large Language Models (LLMs) to monitor robotic environments. By converting visual scenes into natural language descriptions, the system identifies high-level failure modes, such as a stop sign printed on a billboard, which traditional detectors typically miss. Our results across autonomous driving and robotic manipulation tasks demonstrate that LLMs significantly outperform statistical OOD baselines in detecting complex semantic edge cases.

Introduction

Robotic systems operating in open-world environments frequently encounter "edge cases" that lead to operational failures. Most existing safety monitors rely on statistical OOD detection, which identifies anomalies based on pixel-level distribution shifts or model uncertainty. While effective for identifying never-before-seen objects, these methods are often "semantically blind." For instance, an autonomous vehicle might correctly detect a stop sign but fail to realize it is being carried in the bed of a truck and should be ignored.

These semantic anomalies represent a failure of reasoning rather than perception. To address this, we propose using LLMs as a semantic reasoning layer. By utilizing the extensive common-sense knowledge captured during LLM pre-training, robots can evaluate the functional relationships between objects and determine if a scene is contextually coherent.

Methodology

The proposed monitoring framework consists of a three-stage pipeline designed to bridge the gap between raw visual data and high-level reasoning:

  1. Visual-to-Text Conversion: The system utilizes an open-vocabulary object detector (e.g., OWL-ViT) to translate the visual scene into a structured textual description. This description includes identified objects and their immediate spatial contexts, such as "a traffic light mounted on the back of a moving truck."
  2. Prompt Engineering with Chain-of-Thought (CoT): These descriptions are integrated into a specialized prompt template. The framework employs Chain-of-Thought reasoning, guiding the LLM to first describe the objects, evaluate their typicality in the given environment, and finally conclude whether the scene constitutes an anomaly.
  3. LLM Inference: The system uses text-davinci-003 as a zero-shot monitor. Because the LLM possesses general world knowledge, it does not require task-specific fine-tuning to recognize that certain object combinations are anomalous or deceptive.

This approach was benchmarked against standard statistical methods, including SCOD (model uncertainty) and Mahalanobis Distance (feature-space distribution analysis).

Experimental Evaluation

Datasets and Environments

The framework was evaluated in two distinct simulation domains:

  • Autonomous Driving (CARLA): Researchers designed 69 scenarios, including nominal driving and five classes of anomalies, such as billboards featuring traffic signs, trucks carrying traffic lights, and unexpected obstacles like airplanes on a roadway.
  • Robotic Manipulation (Ravens/CLIPort): A pick-and-place task where a robotic arm interacts with blocks and bowls. "Semantic distractors" were introduced—objects that mimic the appearance of task-relevant items but lack their functional properties (e.g., a spatula with a head shaped like a block).

Key Results

The LLM-based monitor demonstrated superior performance in identifying context-dependent failures:

  • Driving Performance: In CARLA, the framework achieved a True Positive Rate (TPR) of 0.92, vastly outperforming SCOD (0.30) and Mahalanobis Distance (0.48). It was particularly adept at identifying "trap" scenarios like billboard-mounted signs.
  • Manipulation Performance: The system detected 86% of semantic distractors, compared to only 51% for a standard autoencoder-based anomaly detector.
  • Reasoning Alignment: Qualitative analysis confirmed that the LLM’s CoT explanations aligned with human logic, correctly identifying why a specific scene was anomalous based on functional context rather than just visual appearance.

Discussion and Future Work

While the LLM-based approach offers a significant leap in semantic reasoning, several challenges remain. The system is currently limited by the "textual bottleneck"; if the initial object detector fails to capture a crucial contextual detail, the LLM cannot reason about it. Furthermore, the latency associated with current LLM APIs poses a challenge for high-speed applications like real-time autonomous driving.

Future research will explore the use of Multimodal Foundation Models (e.g., GPT-4V). By processing images directly, these models may bypass the textual bottleneck and identify subtle visual cues that are difficult to describe in words. Additionally, improving the physical grounding of these models—ensuring they understand the specific constraints of the robot's controller—remains a priority for deploying LLM-based monitors in safety-critical systems.

Summary updated

BibTeX
@article{elhafsi2023semantic,
  author = {Amine Elhafsi and Rohan Sinha and Christopher Agia and Edward Schmerling and Issa A. D. Nesnas and Marco Pavone},
  title = {{Semantic anomaly detection with large language models}},
  journal = {Auton. Robots},
  year = {2023},
  doi = {10.1007/s10514-023-10132-6},
}
Figure