Back to Prompt Library
implementation
Initialize Pydantic AI Energy Attribution Agent
Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.
Linked challenge: Pydantic AI & Claude 4 Sonnet Telemetry & Token Power Attribution Engine
Format
Code-aware
Lines
14
Sections
3
Linked challenge
Pydantic AI & Claude 4 Sonnet Telemetry & Token Power Attribution Engine
Prompt source
Original prompt text with formatting preserved for inspection.
14 lines
3 sections
No variables
0 checklist items
from pydantic import BaseModel, Field
from pydantic_ai import Agent
class TelemetryReport(BaseModel):
tenant_id: str
total_joules: float = Field(description="Total energy consumed in Joules")
joules_per_token: float = Field(description="Energy consumed per generated token")
cost_usd: float = Field(description="Electricity cost calculation")
attribution_error_pct: float
# Instantiate agent with Claude 4 Sonnet model backend
agent = Agent(
'anthropic:claude-3-5-sonnet-latest',
result_type=TelemetryReport,
system_prompt="You are a hardware telemetry engineer calculating exact hardware energy attribution per LLM token."
)Adaptation plan
Keep the source stable, then change the prompt in a predictable order so the next run is easier to evaluate.
Keep stable
Hold the task contract and output shape stable so generated implementations remain comparable.
Tune next
Update libraries, interfaces, and environment assumptions to match the stack you actually run.
Verify after
Test failure handling, edge cases, and any code paths that depend on hidden context or secrets.