Relatelang
RelateLang (former RelateScript) is a declarative meta-language designed to streamline the creation of structured and consistent prompts for large language models (LLMs).
Install / Use
/learn @fischerf/RelatelangREADME
RelateLang: A Declarative Meta-Language for Consistent LLM Prompt Engineering
Abstract
RelateLang is a declarative meta-language designed to streamline the creation of structured and consistent prompts for large language models (LLMs).
This paper introduces RelateLang's syntax, highlighting its foundation in relational and predicate logic. By focusing on relationships, conditions, and context, RelateLang bridges the gap between natural language expressiveness and the precision required for effective LLM interaction. It facilitates a novel approach to prompt engineering, where humans and LLMs collaboratively develop structured prompts that can be easily modified and reused for diverse tasks, enhancing the reliability and automation capabilities of LLM-driven workflows. The language is particularly valuable in scenarios requiring structured input, chain-of-thought guidance, and maintainable prompt management in production systems.
1. Introduction
In the rapidly evolving field of large language models (LLMs), the effectiveness of interactions heavily relies on the quality of prompts. Traditional imperative programming languages often impose rigid structures that contrast with the nuanced and context-sensitive nature of human reasoning. While natural language offers unparalleled flexibility for interacting with LLMs, it can lead to ambiguity and inconsistency in prompt outputs. To address these challenges, we introduce RelateLang, a declarative meta-language specifically designed for crafting structured prompts. RelateLang enables users to define entities, relationships, and conditions in a format that is both readable and logically precise. RelateLang is not intended as a traditional programming language with a separate parser, but rather as a structured input format that leverages the inherent understanding capabilities of LLMs.
1.1 Motivation
RelateLang addresses the growing need for a more systematic and reliable approach to prompt engineering. As LLMs become increasingly sophisticated, the ability to articulate complex instructions and define precise conditions becomes crucial for harnessing their full potential. RelateLang provides an accessible and intuitive way of describing relationships and dependencies between entities, enabling users to express intricate logic in a manner that aligns closely with human reasoning.
The language serves multiple purposes:
- Structured Input: When ambiguity needs to be minimized
- Chain-of-Thought Guidance: Leading LLMs through multi-step reasoning processes
- Maintainable Integration: Standardizing prompts across development teams
With a syntax designed for readability, RelateLang empowers users to generate consistent prompts, making it particularly suited for building reusable prompt templates that can be adapted for different scenarios, thus enhancing the efficiency and reliability of LLM interactions.
1.2 The Challenge of Prompt Consistency
Consider a practical example from software development. When multiple developers embed LLM prompts in production code, linguistic and structural differences emerge:
// Developer 1 (German native speaker)
String prompt = "The customer has bought items for 1500 euros last month. " +
"He lives in Berlin which is a big city. Check if customer " +
"is premium when he buys more than 1000 euro.";
// Developer 2 (Indian English)
String prompt = "Customer has a purchase history of 1500 euros in previous month. " +
"Customer's location is Berlin (metropolitan city). " +
"Kindly verify premium status for purchases exceeding 1000 euros.";
// Developer 3 (American, after refactoring)
String prompt = "Given: A customer from Berlin (major city) with $1500 in purchases " +
"last month. Task: Determine premium status (threshold: $1000).";
All three prompts attempt the same logic, but with different linguistic styles, structures, and even currency assumptions. This creates:
- Maintenance nightmares: Which version is correct? What's the actual threshold?
- Review difficulties: Code reviewers struggle to verify prompt logic
- Testing challenges: Inconsistent outputs from semantically equivalent prompts
- Onboarding issues: New developers must decipher various prompt styles
This standardization becomes crucial as teams scale and prompts encode important business logic.
1.3 RelateLang: Standardizing Prompts as Code
RelateLang solves this by providing a structured format that transcends linguistic differences:
String prompt = """
define Customer as "A person who purchases products".
Customer has monthly_purchases of 1500.
Customer has location of "Berlin".
define PremiumCustomer as "Customer with high purchase value".
if Customer has monthly_purchases > 1000,
then ensure Customer is PremiumCustomer.
""";
This approach mirrors how SQL standardized database queries across teams—you don't write "Please get me all customers from Berlin," you write SELECT * FROM customers WHERE city = 'Berlin'. RelateLang applies this principle to LLM prompts.
1.4 Key Benefits for Production Systems
- Language-Agnostic Structure: Developers from any linguistic background write identical structures
- Code Review Friendly: Business logic is explicit and reviewable
- Testable: Prompt logic can be unit tested like any other code
- Maintainable: Changes to business rules have clear, single update points
- Version Control Friendly: Structured format produces clean diffs
2. Language Design
2.1 Design Principles for Production Use
RelateLang's syntax prioritizes:
- Clarity over brevity: Explicit is better than implicit
- Standardization over flexibility: One way to express common patterns
- Readability: Non-technical stakeholders can understand business logic
- LLM-native interpretation: No parsing or compiler needed; LLMs understand directly
2.2 Syntax
The syntax of RelateLang emphasizes natural language structure, allowing for readable declarations of entities, relationships, and conditions. Its main constructs include:
- Definitions:
define <Entity> as <Description>. - Predicates:
<Entity> is <Predicate>. - Attributes:
<Entity> has <Attribute> of <Value>. - Relations:
relate <Entity1> and <Entity2> as <RelationType> [ if <Condition> ]. - Conditions:
if <Condition>, then <Action>. - Goals:
ensure <Goal>.
2.3 eBNF Grammar
The following Extended Backus-Naur Form (eBNF) defines RelateLang's core syntax:
program ::= { statement } ;
statement ::= definition | predicate | attribute | relation | condition | goal ;
definition ::= "define" entity "as" string "." ;
predicate ::= entity "is" predicate_value "." ;
attribute ::= entity "has" attribute_name "of" attribute_value "." ;
relation ::= "relate" entity "and" entity "as" relation_type [ "if" condition_expr ] "." ;
condition ::= "if" condition_expr ", then" action "." ;
goal ::= "ensure" goal_expr "." ;
condition_expr ::= natural_expression ;
goal_expr ::= natural_expression ;
action ::= "ensure" natural_expression ;
natural_expression ::= { word | property_access | number | string } ;
property_access ::= entity "." attribute_name ;
entity ::= identifier ;
predicate_value ::= identifier | string ;
attribute_name ::= identifier ;
attribute_value ::= identifier | number | string ;
relation_type ::= string ;
word ::= identifier ;
identifier ::= ( lowercase-char | uppercase-char ) { lowercase-char | uppercase-char | digit | "_" } ;
string ::= '"' { character } '"' ;
number ::= [ "-" ] digit { digit } [ "." digit { digit } ] ;
character ::= lowercase-char | uppercase-char | digit | special-char | " " ;
lowercase-char ::= "a" | "b" | "..." | "z" ;
uppercase-char ::= "A" | "B" | "..." | "Z" ;
special-char ::= "-" | "_" | "'" | "," | ":" | ";" | "!" | "?" | "/" | "(" | ")" | ">" | "<" | "=" | "*" | "+" ;
digit ::= "0" | "1" | "..." | "9" ;
Design Philosophy:
This grammar captures RelateLang's essential structure while maintaining the flexibility needed for LLM interpretation. Complex expressions, operators, and logic are handled as natural_expression - allowing LLMs to interpret conditions, comparisons, and actions using their natural language understanding rather than rigid parsing rules.
2.4 Explanations of the Rules
-
Main structure (
program): A program (prompt) consists of a sequence ofstatements, each of which defines a particular piece of information, relationship, or statement. -
Statements:
- Definition (
definition): Defines an entity with a name and a description. - Predicate (
predicate): Assigns a property or state to an entity. - Attributes (
attribute): Associates an entity with an attribute and its value. - Relationships (
relation): Defines a relationship between two entities, optionally with a condition. - Conditions (
condition): Defines a condition and a resulting action. - Goals (
goal): Describes a goal that is to be achieved.
- Expression rules:
- Condition expressions (
condition_expr): Checks relationships or properties between entities. - Goal expressions (
goal_expr): Describes what is to be achieved. - Actions (
action): Relates to the goal that is to be fulfilled.
- Basic structures:
entity,predicate_value,attribute_name,attribute_valueandrelation_typeare basic components represented by identifiers (e.g. names) or values (such as numbers).
- Operators:
predicate_operator,attribute_operator, andrelation_operatordefine the type of relationships or conditions, e.g. "is", "has", "relates to".
Security Score
Audited on Mar 26, 2026
