21:19:30

Safer Prompting & Precise Time Context

Published on 2026-01-23 08:35:51

🛡️ Crash-Proof Prompt Formatting

The most significant change in this release is the implementation of a Safe Prompt Formatting system in the AiTradingService. Previously, if a custom prompt template in prompts.toml referenced a variable that the backend did not provide (e.g., {volume} or {rsi}), the application would crash with a KeyError.

  • Smart Fallbacks: The system now uses a SafePromptDict combined with format_map. If a template requests a missing variable, the system intercepts the error, logs a warning for the developer, and silently replaces the missing key with an empty string.
  • Uninterrupted Service: This ensures that outdated or malformed prompt templates no longer cause runtime exceptions, keeping the trading loop active even during configuration mishaps.

⏱️ Precise Data Time Context

The strategy for providing time context to the AI has been refined to better support multi-symbol analysis.

  • Embedded Timestamps: The global "Current Analysis Time" header has been removed from the start of the user prompt. instead, a Current Time field is now injected directly into the candle/market data block for each specific symbol (=== SYMBOL: BTC ===).
  • Data Synchronicity: The timestamp now prioritizes the actual ticker timestamp from the data feed. If that is unavailable, it gracefully falls back to the system's UTC time. This change ensures the AI understands exactly when the specific data point it is analyzing occurred, rather than just when the prompt was constructed.

🧹 Legacy Variable Support

To ensure backward compatibility with older custom prompts, several deprecated variables have been explicitly shimmed:

  • current_time
  • volume
  • rsi
  • market_summary
  • position_summary

These variables now resolve to empty strings instead of errors, allowing users to transition their prompt templates at their own pace without breaking functionality.

Comments (0)

No comments yet. Be the first to share your thoughts!

Please log in to leave a comment.