mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-24 12:01:54 +00:00
fix(core): better error message for empty var names (#32073)
Previously, we hit an index out of range error with empty variable names (accessing tag[0]), now we through a slightly nicer error --------- Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
@@ -2,6 +2,7 @@ from functools import partial
|
||||
from inspect import isclass
|
||||
from typing import Any, Union, cast
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain_core.language_models import FakeListChatModel
|
||||
@@ -10,6 +11,7 @@ from langchain_core.load.load import loads
|
||||
from langchain_core.messages import HumanMessage
|
||||
from langchain_core.prompts.structured import StructuredPrompt
|
||||
from langchain_core.runnables.base import Runnable, RunnableLambda
|
||||
from langchain_core.utils.mustache import ChevronError
|
||||
from langchain_core.utils.pydantic import is_basemodel_subclass
|
||||
|
||||
|
||||
@@ -128,3 +130,8 @@ def test_structured_prompt_template_format() -> None:
|
||||
assert prompt.invoke({"person": {"name": "foo"}}).to_messages() == [
|
||||
HumanMessage("hi foo")
|
||||
]
|
||||
|
||||
|
||||
def test_structured_prompt_template_empty_vars() -> None:
|
||||
with pytest.raises(ChevronError, match="empty tag"):
|
||||
StructuredPrompt([("human", "hi {{}}")], schema={}, template_format="mustache")
|
||||
|
Reference in New Issue
Block a user