Menu

1 / 2

Contract-First vs Assertion-First: LLM Agent Reliability

DEV Community·Jonny·6 months ago
#ueVUU5Au
#ai#python#devops#security#first
Reading 0:00
15s threshold

When an agent pipeline fails in production, the question is: where was correctness being enforced, and when did it break down?

Two approaches. Different tradeoffs.

Assertion-First

async def score_company ( state : dict ) -> dict : assert state . get ( " enriched " ), " must be enriched before scoring "

result = await llm . run ( score_prompt , state )

assert result . get ( " score " ) is not None return { ** state , ** result }

Enter fullscreen mode

Exit fullscreen mode

Fast to write. Familiar. Works fine for small pipelines.

Problems at scale: checks scatter across every executor. When a pipeline crashes mid-run, you restart from the beginning — including any external API calls already executed. When the assertion fires, you get a stack trace.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.