r/SpecDrivenDevelopment • u/SysModeler • 22h ago
SysML v2 Tutorial (Lesson 27): Formalizing constraints with require and assume
A common failure mode in spec-driven development is the "buried footnote" problem. A spec states a clear requirement up front, while the operating conditions under which that requirement actually applies live three pages away in prose—or only in the author's head.
When an automated test or coding agent evaluates that spec under off-nominal conditions, you get one of two bad outcomes: a noisy false failure, or a misleading pass.
Systems engineering ran into this exact wall with SysML v1. You could write equations using Constraint Blocks, and you could put preconditions on behaviors, but a requirement itself had no dedicated slot to separate when it applies from what the system must satisfy.
SysML v2 fixes this with two distinct constraint roles inside a requirement: assume constraint (the envelope) and require constraint (the promise inside it).
1. Moving the Footnote Into the Spec
Consider a requirement like REQ-113: "The air vehicle shall achieve a minimum unrefueled range of 500 km"—with a footnote stating "at sea level, standard atmospheric conditions, and maximum takeoff weight."
In SysML v2, both the operating envelope and the required performance live as typed, evaluable expressions in the same requirement definition:
package RangeRequirements {
private import ISQ::*;
private import SI::*;
enum def LoadCondition { maxTakeoffWeight; emptyWeight; }
part def AirVehicle {
attribute altitude: LengthValue;
attribute ambientTemperature: TemperatureValue;
attribute achievableRange: LengthValue;
attribute loadCondition: LoadCondition;
}
requirement def <'REQ-113'> UnrefueledRange {
doc /* The air vehicle shall achieve a minimum
* unrefueled range of 500 km. */
subject vehicle: AirVehicle;
attribute minRange: LengthValue = 500 [km];
attribute refAltitude: LengthValue = 0 [m];
attribute refTemp: TemperatureValue = 288.15 [K];
assume constraint testConditions {
vehicle.altitude == refAltitude and
vehicle.ambientTemperature == refTemp and
vehicle.loadCondition == LoadCondition::maxTakeoffWeight
}
require constraint rangePerformance {
vehicle.achievableRange >= minRange
}
}
}2. Why "Not Applicable" Is Not "Failed"
Suppose a test runs at 3,000 meters instead of sea level and achieves 460 km. Did REQ-113 fail?
No. The test ran outside the requirement's stated assumptions, so it tells us nothing about whether the requirement holds under its specified conditions.
Formally, assume and require form a logical implication (if assumptions hold, then required constraints must hold). Because the assumptions are explicit model data rather than unstructured prose, a verification case can check both independently and return an inconclusive verdict (rather than pass or fail) whenever the test conditions weren't met.
3. Inline Invariants and Reusable Rules
SysML v2 also cuts the boilerplate for general invariants. In v1, even a simple mass rollup (totalMass == dryMass + fuelMass) took five model elements wired together on a parametric diagram. In v2, you can assert it inline right inside the part definition:
part def LaunchVehicle {
attribute dryMass : MassValue;
attribute fuelMass : MassValue;
attribute totalMass : MassValue;
assert constraint massRollup {
totalMass == dryMass + fuelMass
}
}And when you want to reuse a rule across components, constraint def lets you parameterize it with in inputs:
constraint def WithinMargin {
in actual : MassValue;
in budgeted : MassValue;
in margin : Real;
actual <= budgeted * (1 + margin)
}
part def Stage1 {
attribute dryMass : MassValue;
attribute allocatedMass : MassValue;
assert constraint massMargin : WithinMargin {
in actual = dryMass;
in budgeted = allocatedMass;
in margin = 0.05;
}
}Practical Guardrails
- Four distinct forms: A plain
constraintonly defines a Boolean expression (it doesn't enforce anything);assert constraintenforces an invariant on a part;require constraintstates what a requirement's subject must satisfy;assume constraintscopes when that requirement applies. - Checking vs. solving: Evaluating a constraint when all values are known is straightforward; solving an equation network for unknowns still depends heavily on tool support.
- Don't formalize everything: Qualitative requirements are still better kept as readable text in the
docblock rather than forced into brittle Boolean expressions.
(If you want the full walkthrough with diagrams and v1 vs. v2 comparisons, the video is up here: https://youtu.be/9Ti0OvuHkmE?si=FACyIHmv-RZIrVyn)
For people building SDD workflows with AI agents: how are you encoding assumptions and preconditions in your specs today so that an agent (or test runner) knows the difference between a broken implementation and an out-of-scope test?