Home / Function/ __init__() — langchain Function Reference

__init__() — langchain Function Reference

Architecture documentation for the __init__() function in openai_moderation.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  69d1d9f6_fb86_46bf_8942_09260a415089["__init__()"]
  48713c67_3a9a_ec9e_ec74_46e6955f07bd["OpenAIModerationMiddleware"]
  69d1d9f6_fb86_46bf_8942_09260a415089 -->|defined in| 48713c67_3a9a_ec9e_ec74_46e6955f07bd
  style 69d1d9f6_fb86_46bf_8942_09260a415089 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/middleware/openai_moderation.py lines 52–88

    def __init__(
        self,
        *,
        model: ModerationModel = "omni-moderation-latest",
        check_input: bool = True,
        check_output: bool = True,
        check_tool_results: bool = False,
        exit_behavior: Literal["error", "end", "replace"] = "end",
        violation_message: str | None = None,
        client: OpenAI | None = None,
        async_client: AsyncOpenAI | None = None,
    ) -> None:
        """Create the middleware instance.

        Args:
            model: OpenAI moderation model to use.
            check_input: Whether to check user input messages.
            check_output: Whether to check model output messages.
            check_tool_results: Whether to check tool result messages.
            exit_behavior: How to handle violations
                (`'error'`, `'end'`, or `'replace'`).
            violation_message: Custom template for violation messages.
            client: Optional pre-configured OpenAI client to reuse.
                If not provided, a new client will be created.
            async_client: Optional pre-configured AsyncOpenAI client to reuse.
                If not provided, a new async client will be created.
        """
        super().__init__()
        self.model = model
        self.check_input = check_input
        self.check_output = check_output
        self.check_tool_results = check_tool_results
        self.exit_behavior = exit_behavior
        self.violation_message = violation_message

        self._client = client
        self._async_client = async_client

Domain

Subdomains

Frequently Asked Questions

What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/middleware/openai_moderation.py.
Where is __init__() defined?
__init__() is defined in libs/partners/openai/langchain_openai/middleware/openai_moderation.py at line 52.

Analyze Your Own Codebase

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

Try Supermodel Free