Skip to content

bug: RunnableRails.atransform is not returning an async interator #1692

@sfitts

Description

@sfitts

Did you check docs and existing issues?

  • I have read all the NeMo-Guardrails docs
  • I have updated the package to the latest version before submitting this issue
  • (optional) I have used the develop branch
  • I have searched the existing issues of NeMo-Guardrails

Python version (python --version)

Python 3.12.9

Operating system/version

Windows 11

NeMo-Guardrails version (if you must use a specific version and not the latest

0.20.0

Describe the bug

When using RunnableRails in any chain that uses a RunnableSequence we see the following error:

TypeError: 'async for' requires an object with __aiter__ method, got coroutine

The issue seems to have been introduced with version 0.17.0. I've attached a reproduction involving just LC and NemoRails (full disclosure, it was generated by Claude Code, though I've edited it a bit for brevity and I am a person ;)).

Steps To Reproduce

import asyncio
import inspect

from langchain_core.runnables import RunnableLambda
from nemoguardrails import RailsConfig
from nemoguardrails.integrations.langchain.runnable_rails import RunnableRails

async def reproduce_bug():
    print("=== Bug reproduction ===")
    config = RailsConfig.from_content(yaml_content="models: []")
    rails = RunnableRails(config, passthrough=True)

    # Putting RunnableRails in a sequence triggers atransform via astream
    pipeline = RunnableLambda(lambda x: x) | rails

    try:
        async for _ in pipeline.astream("hello"):
            pass
        print("No error — bug not reproduced (unexpected)")
    except TypeError as e:
        print(f"TypeError (expected): {e}")
    print()


if __name__ == "__main__":
    asyncio.run(reproduce_bug())

Expected Behavior

When run, the above code should output "No error -- bug not reproduced".

Actual Behavior

The current output is:

$ python  nemo_atransform_repro.py
=== Bug reproduction ===
No main LLM specified in the config and no LLM provided via constructor.
TypeError (expected): 'async for' requires an object with __aiter__ method, got coroutine
<path elided>/nemo_atransform_repro.py:21: RuntimeWarning: coroutine 'RunnableRails.atransform' was never awaited
  print(f"TypeError (expected): {e}")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstatus: needs triageNew issues that have not yet been reviewed or categorized.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions