Home / Function/ get_query_constructor_prompt() — langchain Function Reference

get_query_constructor_prompt() — langchain Function Reference

Architecture documentation for the get_query_constructor_prompt() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  445d6da1_3574_d2ff_dd74_d9fd7b77b470["get_query_constructor_prompt()"]
  7225abf9_cc63_55f0_0ae9_9fa5685b39ff["base.py"]
  445d6da1_3574_d2ff_dd74_d9fd7b77b470 -->|defined in| 7225abf9_cc63_55f0_0ae9_9fa5685b39ff
  7c645a0f_77f7_93a6_94ee_217db357131a["load_query_constructor_chain()"]
  7c645a0f_77f7_93a6_94ee_217db357131a -->|calls| 445d6da1_3574_d2ff_dd74_d9fd7b77b470
  8be56ad0_9949_1505_8cd9_95bdbee1ff5d["load_query_constructor_runnable()"]
  8be56ad0_9949_1505_8cd9_95bdbee1ff5d -->|calls| 445d6da1_3574_d2ff_dd74_d9fd7b77b470
  49687e6c_2a11_66de_8bee_b6d94d792ecb["_format_attribute_info()"]
  445d6da1_3574_d2ff_dd74_d9fd7b77b470 -->|calls| 49687e6c_2a11_66de_8bee_b6d94d792ecb
  6099571f_d26c_8e92_ce74_513ecf22a75e["construct_examples()"]
  445d6da1_3574_d2ff_dd74_d9fd7b77b470 -->|calls| 6099571f_d26c_8e92_ce74_513ecf22a75e
  style 445d6da1_3574_d2ff_dd74_d9fd7b77b470 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/query_constructor/base.py lines 201–265

def get_query_constructor_prompt(
    document_contents: str,
    attribute_info: Sequence[AttributeInfo | dict],
    *,
    examples: Sequence | None = None,
    allowed_comparators: Sequence[Comparator] = tuple(Comparator),
    allowed_operators: Sequence[Operator] = tuple(Operator),
    enable_limit: bool = False,
    schema_prompt: BasePromptTemplate | None = None,
    **kwargs: Any,
) -> BasePromptTemplate:
    """Create query construction prompt.

    Args:
        document_contents: The contents of the document to be queried.
        attribute_info: A list of AttributeInfo objects describing
            the attributes of the document.
        examples: Optional list of examples to use for the chain.
        allowed_comparators: Sequence of allowed comparators.
        allowed_operators: Sequence of allowed operators.
        enable_limit: Whether to enable the limit operator.
        schema_prompt: Prompt for describing query schema. Should have string input
            variables allowed_comparators and allowed_operators.
        kwargs: Additional named params to pass to FewShotPromptTemplate init.

    Returns:
        A prompt template that can be used to construct queries.
    """
    default_schema_prompt = (
        SCHEMA_WITH_LIMIT_PROMPT if enable_limit else DEFAULT_SCHEMA_PROMPT
    )
    schema_prompt = schema_prompt or default_schema_prompt
    attribute_str = _format_attribute_info(attribute_info)
    schema = schema_prompt.format(
        allowed_comparators=" | ".join(allowed_comparators),
        allowed_operators=" | ".join(allowed_operators),
    )
    if examples and isinstance(examples[0], tuple):
        examples = construct_examples(examples)
        example_prompt = USER_SPECIFIED_EXAMPLE_PROMPT
        prefix = PREFIX_WITH_DATA_SOURCE.format(
            schema=schema,
            content=document_contents,
            attributes=attribute_str,
        )
        suffix = SUFFIX_WITHOUT_DATA_SOURCE.format(i=len(examples) + 1)
    else:
        examples = examples or (
            EXAMPLES_WITH_LIMIT if enable_limit else DEFAULT_EXAMPLES
        )
        example_prompt = EXAMPLE_PROMPT
        prefix = DEFAULT_PREFIX.format(schema=schema)
        suffix = DEFAULT_SUFFIX.format(
            i=len(examples) + 1,
            content=document_contents,
            attributes=attribute_str,
        )
    return FewShotPromptTemplate(
        examples=list(examples),
        example_prompt=example_prompt,
        input_variables=["query"],
        suffix=suffix,
        prefix=prefix,
        **kwargs,
    )

Subdomains

Frequently Asked Questions

What does get_query_constructor_prompt() do?
get_query_constructor_prompt() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/query_constructor/base.py.
Where is get_query_constructor_prompt() defined?
get_query_constructor_prompt() is defined in libs/langchain/langchain_classic/chains/query_constructor/base.py at line 201.
What does get_query_constructor_prompt() call?
get_query_constructor_prompt() calls 2 function(s): _format_attribute_info, construct_examples.
What calls get_query_constructor_prompt()?
get_query_constructor_prompt() is called by 2 function(s): load_query_constructor_chain, load_query_constructor_runnable.

Analyze Your Own Codebase

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

Try Supermodel Free