LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    โŒ˜I

    Chat LangChain

    What can I help with?

    Enter to sendยทShift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coredecisionstypesChoice
    Classโ—Since v1.8

    Choice

    Copy
    Choice()

    Bases

    BaseModel

    Used in Docs

    • Google Gemini Decisions integration
    • OpenAI Decisions integration
    • TypeSafe integrations

    Attributes

    View source on GitHub
    attribute
    model_config
    attribute
    type: Literal['choice']
    attribute
    criteria: dict[str, JsonValue]
    attribute
    instructions: Content

    Select one label from a fixed set of alternatives.

    Use Choice for categorical decisions with no inherent ordering, such as routing a support request, detecting a document type, or selecting an intent. The answer includes the selected label, a probability for every supplied label, and a confidence value.

    Route a support request
    from langchain_core.decisions import Choice
    
    response = classifier.invoke(
        {
            "state": "Stripe fails whenever I connect my account.",
            "questions": {
                "department": Choice(
                    instructions="Which team should handle this request?",
                    criteria={
                        "billing": "Payment, invoice, or subscription issues.",
                        "technical": "Product bugs or integration failures.",
                        "sales": "Pricing or purchasing questions.",
                    },
                )
            },
        }
    )
    department = response.choices["department"]
    
    if department.confidence >= 0.7:
        route_to(department.choice)
    else:
        route_to_human_triage()

    Wire discriminator for a categorical question.

    Candidate labels mapped to their descriptions.

    Descriptions may be text, structured JSON, or None. Include an other or none_of_the_above label when the supplied alternatives may not cover every input.

    Complete categorical judgment to make about the input state.