diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index 3f64a2b14..bba7bcd33 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -783,7 +783,7 @@ def process_block_body( if state.yield_result and not iteration_state.yield_result: yield_result(result, block.kind) case MessageBlock(): - content, _, scope, trace = process_block_of( + content, _, _, trace = process_block_of( block, "content", state, diff --git a/tests/test_messages.py b/tests/test_messages.py index 65125e034..0b98dbed6 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -147,3 +147,48 @@ def test_messages5(): "pdl__defsite": "array.0.message", } ] + + +def test_messages6(): + prog_str = """ +description: Message block scope +defs: + x: 1 +array: + - content: + defs: + x: 2 + text: ${ x } + - content: + text: ${ x } +""" + result = exec_str(prog_str, output="all") + context = result["scope"]["pdl_context"] + assert [m.serialize(SerializeMode.LITELLM) for m in result["result"]] == [ + [ + { + "role": "user", + "content": "2", + "pdl__defsite": "array.0.message", + } + ], + [ + { + "role": "user", + "content": "1", + "pdl__defsite": "array.1.message", + } + ], + ] + assert context.serialize(SerializeMode.LITELLM) == [ + { + "role": "user", + "content": "2", + "pdl__defsite": "array.0.message", + }, + { + "role": "user", + "content": "1", + "pdl__defsite": "array.1.message", + }, + ]