Module: RailsAiBridge::Serializers::AntiHallucinationRules
- Defined in:
- lib/rails_ai_bridge/serializers/anti_hallucination_rules.rb,
lib/rails_ai_bridge/serializers/anti_hallucination_rules/section_formatter.rb
Overview
Single source of truth for the anti-hallucination rules injected into
every generated context file (markdown and JSON). Keeps AI assistants
verifying against the live application through the rails_* MCP tools
instead of inventing structure.
Controlled by Config::Output#anti_hallucination_rules (default true).
Defined Under Namespace
Classes: SectionFormatter
Constant Summary collapse
- HEADING =
Consistent named section heading used across all markdown outputs.
'## Anti-hallucination rules'- RULES =
[ '- Verify before you write (column, association, route, helper, gem).', '- Mark assumptions with `[ASSUMPTION]`. Silent guesses are forbidden.', '- This app is not average Rails. Query conventions and gems before scaffolding.', '- Check the inheritance chain (filters, concerns, STI) before editing a controller or model.', '- Empty tool output is information, not permission to invent.', '- Re-query after writes. Stale tool output lies.' ].freeze
Class Method Summary collapse
-
.enabled? ⇒ Boolean
truewhen the rules block should be injected. -
.markdown_block ⇒ String?
Markdown section as a string, suitable for splicing into a document after the header/intro and before content sections.
-
.markdown_lines ⇒ Array<String>
Markdown lines for the named section, with a trailing blank line.
-
.rules ⇒ Array<String>
Rule bullets without the heading.
Class Method Details
.enabled? ⇒ Boolean
Returns true when the rules block should be injected.
28 29 30 |
# File 'lib/rails_ai_bridge/serializers/anti_hallucination_rules.rb', line 28 def enabled? RailsAiBridge.configuration.anti_hallucination_rules end |
.markdown_block ⇒ String?
Markdown section as a string, suitable for splicing into a document after the header/intro and before content sections.
54 55 56 57 58 |
# File 'lib/rails_ai_bridge/serializers/anti_hallucination_rules.rb', line 54 def markdown_block return nil unless enabled? markdown_lines.join("\n").chomp end |
.markdown_lines ⇒ Array<String>
Markdown lines for the named section, with a trailing blank line.
44 45 46 47 48 |
# File 'lib/rails_ai_bridge/serializers/anti_hallucination_rules.rb', line 44 def markdown_lines return [] unless enabled? [HEADING, '', *RULES, ''] end |
.rules ⇒ Array<String>
Rule bullets without the heading.
35 36 37 38 39 |
# File 'lib/rails_ai_bridge/serializers/anti_hallucination_rules.rb', line 35 def rules return [].freeze unless enabled? RULES end |