Skip to content

feat: add support for system messages to RunnableRails #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

smruthi33
Copy link

@smruthi33 smruthi33 commented Apr 10, 2025

Description

The current implementation does not support messages that have a System Message

guardrails_config = RailsConfig.from_path(<Path>)
guardrails = RunnableRails(guardrails_config)
client = ChatOpenAI(
                base_url=GEN_AI_ENDPOINT,
                api_key=GEN_AI_ENDPOINT_AUTHORIZATION,
                model= MODEL_NAME,
                temperature=0                
            )
messages = [
                (
                    "system", system
                )
                ,(
                    "human", prompt
                )
            ]
prompt = ChatPromptTemplate.from_messages(messages)

chain_with_guardrails =  prompt | (guardrails | client)

In this setup, RunnableRails does not handle messages containing system roles. Attempting to pass such a structure as a dictionary causes conflicts with the format expected by the Runnable interface from LangChain, which assumes a flat input structure and does not support multiple message types out of the box. This change addresses that limitation.

Related Issue(s)

Checklist

  • I've read the CONTRIBUTING guidelines.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • @mentions of the person or team responsible for reviewing proposed changes.

@Pouyanpi
Copy link
Collaborator

Thank you @smruthi33 for opening this PR 🚀

Would be great if you can add a test to test_runnable_rails.py. Thank you!

@Pouyanpi Pouyanpi changed the title Adding support for system message feat: add support for system messages in RunnableRails Apr 10, 2025
@Pouyanpi Pouyanpi changed the title feat: add support for system messages in RunnableRails feat: add support for system messages to RunnableRails Apr 10, 2025
@Pouyanpi Pouyanpi self-requested a review April 11, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants