Home / Class/ OpenAIModerationError Class — langchain Architecture

OpenAIModerationError Class — langchain Architecture

Architecture documentation for the OpenAIModerationError class in openai_moderation.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ffb9e160_0b08_1372_1ae2_759eeca3f585["OpenAIModerationError"]
  01be0f4d_c758_ee37_da2c_7b4f18d7fa84["openai_moderation.py"]
  ffb9e160_0b08_1372_1ae2_759eeca3f585 -->|defined in| 01be0f4d_c758_ee37_da2c_7b4f18d7fa84
  b2963e52_26ea_cd36_4db4_7c0118b3e386["__init__()"]
  ffb9e160_0b08_1372_1ae2_759eeca3f585 -->|method| b2963e52_26ea_cd36_4db4_7c0118b3e386

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/middleware/openai_moderation.py lines 24–46

class OpenAIModerationError(RuntimeError):
    """Raised when OpenAI flags content and `exit_behavior` is set to ``"error"``."""

    def __init__(
        self,
        *,
        content: str,
        stage: ViolationStage,
        result: Moderation,
        message: str,
    ) -> None:
        """Initialize the error with violation details.

        Args:
            content: The content that was flagged.
            stage: The stage where the violation occurred.
            result: The moderation result from OpenAI.
            message: The error message.
        """
        super().__init__(message)
        self.content = content
        self.stage = stage
        self.result = result

Frequently Asked Questions

What is the OpenAIModerationError class?
OpenAIModerationError is a class in the langchain codebase, defined in libs/partners/openai/langchain_openai/middleware/openai_moderation.py.
Where is OpenAIModerationError defined?
OpenAIModerationError is defined in libs/partners/openai/langchain_openai/middleware/openai_moderation.py at line 24.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free