sentinel_rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +10 -0
  4. data/.rubocop_todo.yml +72 -0
  5. data/.sentinel-test.yml +20 -0
  6. data/.sentinel.yml +29 -0
  7. data/.sentinel.yml.example +74 -0
  8. data/AGENTS.md +87 -0
  9. data/CODE_OF_CONDUCT.md +132 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +226 -0
  12. data/Rakefile +12 -0
  13. data/docs/architecture.md +130 -0
  14. data/docs/development.md +376 -0
  15. data/docs/usage.md +238 -0
  16. data/exe/sentinel_rb +6 -0
  17. data/lib/sentinel_rb/analyzer.rb +140 -0
  18. data/lib/sentinel_rb/analyzers/base.rb +53 -0
  19. data/lib/sentinel_rb/analyzers/base_model_usage.rb +188 -0
  20. data/lib/sentinel_rb/analyzers/dangerous_tools.rb +283 -0
  21. data/lib/sentinel_rb/analyzers/few_shot_bias.rb +75 -0
  22. data/lib/sentinel_rb/analyzers/irrelevant_info.rb +164 -0
  23. data/lib/sentinel_rb/analyzers/misinformation.rb +220 -0
  24. data/lib/sentinel_rb/cli.rb +151 -0
  25. data/lib/sentinel_rb/client/base.rb +34 -0
  26. data/lib/sentinel_rb/client/mock.rb +167 -0
  27. data/lib/sentinel_rb/client/openai.rb +167 -0
  28. data/lib/sentinel_rb/client.rb +25 -0
  29. data/lib/sentinel_rb/config.rb +64 -0
  30. data/lib/sentinel_rb/report.rb +224 -0
  31. data/lib/sentinel_rb/version.rb +5 -0
  32. data/lib/sentinel_rb.rb +39 -0
  33. data/sig/sentinel_rb.rbs +4 -0
  34. data/test_prompts/a2_bad_prompt.md +5 -0
  35. data/test_prompts/a2_good_prompt.md +9 -0
  36. data/test_prompts/a3_bad_prompt.md +19 -0
  37. data/test_prompts/a3_good_prompt.md +15 -0
  38. data/test_prompts/a4_bad_prompt.md +13 -0
  39. data/test_prompts/a4_good_prompt.md +11 -0
  40. data/test_prompts/a5_bad_prompt.md +13 -0
  41. data/test_prompts/a5_good_prompt.md +14 -0
  42. data/test_prompts/bad_prompt.md +15 -0
  43. data/test_prompts/comprehensive_good_prompt.md +11 -0
  44. data/test_prompts/good_prompt.md +9 -0
  45. data/test_prompts/multi_bad_prompt.md +11 -0
  46. data/test_prompts/very_bad_prompt.md +7 -0
  47. metadata +149 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a407a7c7bc6fe36c2602e3e6b459a740c08b34904aa1543d26495261433c42ae
4
+ data.tar.gz: 9e578433b8f22abec3990f212f4ac056d3cc8a431b95ce1af12402b3e0a948e7
5
+ SHA512:
6
+ metadata.gz: a3e78be6292a5da3c33b4763f701cef652067a0e1c27a003e78ddd05feae4d96830f7fb2238ffbef93b09595d56edd6b02115503160c28111b25b74e9fe22cf5
7
+ data.tar.gz: 36eed9031ee2aa2d0f398a419cb6468fa9bbd61eaa20914c8f7d0ddb48edf5a607833bfc695c92e3716512ac52b4ba29d24be7e3a494419cace1820fb28831c2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 3.1
5
+
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ EnforcedStyle: double_quotes
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,72 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --exclude-limit 999999`
3
+ # on 2025-06-06 16:31:26 UTC using RuboCop version 1.76.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 13
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
+ Metrics/AbcSize:
12
+ Max: 87
13
+
14
+ # Offense count: 5
15
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16
+ # AllowedMethods: refine
17
+ Metrics/BlockLength:
18
+ Max: 98
19
+
20
+ # Offense count: 7
21
+ # Configuration parameters: CountComments, CountAsOne.
22
+ Metrics/ClassLength:
23
+ Max: 229
24
+
25
+ # Offense count: 6
26
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 23
29
+
30
+ # Offense count: 36
31
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
32
+ Metrics/MethodLength:
33
+ Max: 84
34
+
35
+ # Offense count: 5
36
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
37
+ Metrics/PerceivedComplexity:
38
+ Max: 23
39
+
40
+ # Offense count: 1
41
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
42
+ # NamePrefix: is_, has_, have_, does_
43
+ # ForbiddenPrefixes: is_, has_, have_, does_
44
+ # AllowedMethods: is_a?
45
+ # MethodDefinitionMacros: define_method, define_singleton_method
46
+ Naming/PredicatePrefix:
47
+ Exclude:
48
+ - 'spec/**/*'
49
+ - 'lib/sentinel_rb/analyzers/few_shot_bias.rb'
50
+
51
+ # Offense count: 1
52
+ # Configuration parameters: AllowedConstants.
53
+ Style/Documentation:
54
+ Exclude:
55
+ - 'spec/**/*'
56
+ - 'test/**/*'
57
+ - 'lib/sentinel_rb.rb'
58
+
59
+ # Offense count: 6
60
+ # This cop supports safe autocorrection (--autocorrect).
61
+ Style/IfUnlessModifier:
62
+ Exclude:
63
+ - 'lib/sentinel_rb/analyzers/irrelevant_info.rb'
64
+ - 'lib/sentinel_rb/cli.rb'
65
+ - 'lib/sentinel_rb/client/mock.rb'
66
+
67
+ # Offense count: 10
68
+ # This cop supports safe autocorrection (--autocorrect).
69
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
70
+ # URISchemes: http, https
71
+ Layout/LineLength:
72
+ Max: 304
@@ -0,0 +1,20 @@
1
+ # Test configuration using mock provider
2
+ provider: mock
3
+ model: mock-model
4
+ relevance_threshold: 0.55
5
+
6
+ # Mock-specific settings
7
+ mock_scores:
8
+ default: 0.7
9
+
10
+ # Standard settings
11
+ dangerous_tools:
12
+ - delete_file
13
+ - transfer_funds
14
+
15
+ skip_patterns:
16
+ - "**/.git/**"
17
+ - "**/node_modules/**"
18
+
19
+ output_format: table
20
+ log_level: warn
data/.sentinel.yml ADDED
@@ -0,0 +1,29 @@
1
+ # SentinelRb Configuration File
2
+ # For complete configuration options, see docs/usage.md
3
+
4
+ # LLM Provider Configuration
5
+ provider: openai
6
+ model: gpt-4o-mini
7
+ api_key_env: OPENAI_API_KEY
8
+
9
+ # Analysis Thresholds
10
+ relevance_threshold: 0.55 # Lower = more strict (0.0 - 1.0)
11
+ divergence_threshold: 0.25 # For few-shot bias detection
12
+
13
+ # Security Settings
14
+ dangerous_tools:
15
+ - delete_file
16
+ - transfer_funds
17
+ - system_shutdown
18
+ - exec_command
19
+
20
+ # File Processing
21
+ skip_patterns:
22
+ - "**/.git/**"
23
+ - "**/node_modules/**"
24
+ - "**/tmp/**"
25
+ - "**/.DS_Store"
26
+
27
+ # Output Settings
28
+ output_format: table # table, json, detailed
29
+ log_level: warn # debug, info, warn, error
@@ -0,0 +1,74 @@
1
+ # SentinelRb Configuration Example
2
+ # Copy this file to .sentinel.yml and customize as needed
3
+
4
+ # LLM Provider Configuration
5
+ provider: openai # Provider: 'openai' or 'mock'
6
+ model: gpt-4o-mini # OpenAI model to use
7
+ api_key_env: OPENAI_API_KEY # Environment variable containing API key
8
+
9
+ # Analysis Thresholds
10
+ relevance_threshold: 0.55 # Threshold for A1 irrelevant information detection (0.0-1.0)
11
+ divergence_threshold: 0.25 # Threshold for A3 few-shot bias detection (0.0-1.0)
12
+ fact_check_threshold: 0.7 # Threshold for A2 fact-checking confidence (0.0-1.0)
13
+
14
+ # A2: Misinformation Detection Keywords (in addition to built-in patterns)
15
+ misinformation_keywords:
16
+ - "conspiracy"
17
+ - "hoax"
18
+ - "debunked"
19
+ - "cover-up"
20
+
21
+ # A4: Base Model Usage Detection Keywords (in addition to built-in patterns)
22
+ instruction_keywords:
23
+ - "jailbreak"
24
+ - "bypass"
25
+ - "ignore"
26
+ - "override"
27
+
28
+ bypass_patterns:
29
+ - "DAN"
30
+ - "developer mode"
31
+ - "god mode"
32
+ - "admin mode"
33
+
34
+ # A5: Dangerous Tools Detection Keywords (in addition to built-in patterns)
35
+ dangerous_keywords:
36
+ - "weapon"
37
+ - "explosive"
38
+ - "hack"
39
+ - "malware"
40
+
41
+ weapon_keywords:
42
+ - "bomb"
43
+ - "grenade"
44
+ - "firearm"
45
+ - "poison"
46
+
47
+ cyber_keywords:
48
+ - "exploit"
49
+ - "ddos"
50
+ - "trojan"
51
+ - "ransomware"
52
+
53
+ # File Processing
54
+ skip_patterns: # Glob patterns to skip during analysis
55
+ - "**/.git/**"
56
+ - "**/node_modules/**"
57
+ - "**/tmp/**"
58
+ - "**/.DS_Store"
59
+ - "**/vendor/**"
60
+ - "**/*.log"
61
+
62
+ # Output Options
63
+ log_level: info # Logging level: debug, info, warn, error
64
+ color_output: true # Enable colored output in terminal
65
+ max_findings_per_file: 50 # Maximum findings to report per file
66
+
67
+ # Output Configuration
68
+ output_format: table # Default output format: 'table', 'json', 'detailed'
69
+ log_level: warn # Log level: 'debug', 'info', 'warn', 'error'
70
+
71
+ # Mock Client Configuration (for testing without API keys)
72
+ mock_scores: # Override scores for specific content patterns
73
+ # Example: Set specific score for test content
74
+ # "test prompt": 0.3
data/AGENTS.md ADDED
@@ -0,0 +1,87 @@
1
+ # SentinelRb Agent Guide
2
+
3
+ ## Overview
4
+
5
+ SentinelRb is an LLM-driven prompt inspector designed to automatically detect common antipatterns in prompts that are difficult to catch with static analysis. This tool helps developers maintain high-quality prompts by identifying issues that could negatively impact LLM performance.
6
+
7
+ ## Core Purpose
8
+
9
+ SentinelRb analyzes prompt files to detect five key antipatterns using OpenAI, RAG, and metadata analysis:
10
+
11
+ - **A1: Irrelevant Information** - Detects prompts containing noisy or off-topic content
12
+ - **A2: Misinformation & Logical Contradictions** - Verifies factual accuracy using RAG knowledge base
13
+ - **A3: Few-shot Bias Order** - Identifies ordering bias in few-shot examples
14
+ - **A4: Base Model Usage** - Flags usage of base models instead of instruction-tuned models
15
+ - **A5: Dangerous Automatic Tool Execution** - Prevents auto-execution of dangerous tools
16
+
17
+ ## Quick Reference
18
+
19
+ ### Installation & Basic Usage
20
+ ```bash
21
+ gem install sentinel_rb
22
+ sentinel --glob "prompts/**/*.{md,json}" --config .sentinel.yml
23
+ ```
24
+
25
+ ### Key Configuration
26
+ ```yaml
27
+ provider: openai
28
+ model: gpt-4o-mini
29
+ relevance_threshold: 0.55
30
+ divergence_threshold: 0.25
31
+ ```
32
+
33
+ ## Detailed Documentation
34
+
35
+ For comprehensive information about SentinelRb, please refer to the following documentation:
36
+
37
+ ### System Architecture
38
+ - **File**: `/docs/architecture.md`
39
+ - **Content**: Detailed technical architecture, component descriptions, analyzer implementations, and extension points
40
+
41
+ ### Usage Guide
42
+ - **File**: `/docs/usage.md`
43
+ - **Content**: Complete usage instructions, configuration options, CLI commands, integration examples, and troubleshooting
44
+
45
+ ### Development Guide
46
+ - **File**: `/docs/development.md`
47
+ - **Content**: Development setup, contributing guidelines, adding new analyzers, testing procedures, and release process
48
+
49
+ ## Key Features for Agents
50
+
51
+ ### Automated Analysis
52
+ - File-based prompt analysis
53
+ - Configurable thresholds and detection rules
54
+ - Multiple output formats (table, JSON, detailed)
55
+
56
+ ### CI/CD Integration
57
+ - GitHub Actions workflow templates
58
+ - Pre-commit hooks
59
+ - Automated quality gates
60
+
61
+ ### Extensibility
62
+ - Pluggable analyzer architecture
63
+ - Custom LLM provider support
64
+ - Configurable rule sets
65
+
66
+ ### Security Focus
67
+ - Dangerous tool detection
68
+ - API key management
69
+ - No persistent data storage
70
+
71
+ ## Agent-Specific Considerations
72
+
73
+ When working with SentinelRb in an agent context:
74
+
75
+ 1. **Configuration Management**: Use environment-specific configurations for different deployment stages
76
+ 2. **Rate Limiting**: Configure appropriate API rate limits to avoid quota exhaustion
77
+ 3. **Error Handling**: Implement robust error handling for API failures and network issues
78
+ 4. **Caching**: Enable response caching for improved performance with repeated analyses
79
+ 5. **Monitoring**: Set up monitoring for analysis results and system health
80
+
81
+ ## Getting Help
82
+
83
+ - **Documentation**: Check `/docs/` directory for detailed guides
84
+ - **Issues**: Report bugs and feature requests via GitHub issues
85
+ - **Examples**: See usage examples in the main README.md file
86
+
87
+ For technical implementation details, architectural decisions, and development procedures, always refer to the comprehensive documentation in the `/docs` directory.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Masumi Kawasaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # SentinelRb
2
+
3
+ SentinelRb is an LLM-driven prompt inspector designed to automatically detect common antipatterns in prompts before they reach production systems.
4
+
5
+ ## Overview
6
+
7
+ SentinelRb analyzes prompt files to detect five key antipatterns using advanced pattern matching and LLM-based analysis:
8
+
9
+ | ID | Target | Detection Logic |
10
+ |----|--------|-----------------|
11
+ | A1 | Irrelevant Information | Uses LLM to generate relevance scores; flags prompts with low focus/clarity |
12
+ | A2 | Misinformation & Logical Contradictions | Detects false information patterns and conspiracy theories |
13
+ | A3 | Few-shot Bias | Analyzes example patterns for demographic or representational bias |
14
+ | A4 | Base Model Usage | Detects jailbreak attempts and instruction bypassing |
15
+ | A5 | Dangerous Tools | Identifies requests for harmful content creation or dangerous activities |
16
+
17
+ ## Features
18
+
19
+ - **Comprehensive Analysis**: Detects 5 major prompt antipatterns
20
+ - **LLM Integration**: Works with OpenAI models for semantic analysis
21
+ - **Mock Mode**: Test without API keys using built-in pattern detection
22
+ - **Multiple Output Formats**: Table, JSON, and detailed reporting
23
+ - **Configurable Thresholds**: Customize sensitivity for each analyzer
24
+ - **CLI & Library**: Use as command-line tool or integrate into your Ruby applications
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```ruby
31
+ gem 'sentinel_rb'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```
37
+ $ bundle install
38
+ ```
39
+
40
+ Or install it yourself as:
41
+
42
+ ```
43
+ $ gem install sentinel_rb
44
+ ```
45
+
46
+ ## Requirements
47
+
48
+ - Ruby >= 3.1.0
49
+ - OpenAI API key (optional - mock mode available for testing)
50
+
51
+ ## Usage
52
+
53
+ ### CLI Usage
54
+
55
+ Analyze prompt files using the command-line interface:
56
+
57
+ ```bash
58
+ # Analyze all markdown files in prompts directory
59
+ sentinel_rb analyze --glob "prompts/**/*.md"
60
+
61
+ # Analyze specific files with custom output format
62
+ sentinel_rb analyze --files prompt1.md prompt2.md --format json
63
+
64
+ # Run specific analyzers only
65
+ sentinel_rb analyze --files test.md --analyzers A1,A2,A5
66
+
67
+ # Use detailed output format
68
+ sentinel_rb analyze --files test.md --format detailed
69
+ ```
70
+
71
+ ### Library Usage
72
+
73
+ Use SentinelRb programmatically in your Ruby applications:
74
+
75
+ ```ruby
76
+ require 'sentinel_rb'
77
+
78
+ # Initialize analyzer with custom config
79
+ config = SentinelRb::Config.load('.sentinel.yml')
80
+ analyzer = SentinelRb::Analyzer.new(config)
81
+
82
+ # Analyze a prompt string
83
+ prompt = "Tell me false information about vaccines"
84
+ findings = analyzer.analyze_prompt(prompt)
85
+
86
+ # Analyze a file
87
+ findings = analyzer.analyze_file('prompt.md')
88
+
89
+ # Run specific analyzers only
90
+ findings = analyzer.analyze_prompt(prompt, analyzer_ids: ['A2', 'A4'])
91
+
92
+ findings.each do |finding|
93
+ puts "#{finding[:level]}: #{finding[:message]}"
94
+ end
95
+ ```
96
+
97
+ ### Configuration
98
+
99
+ Create a `.sentinel.yml` file in your project root:
100
+
101
+ ```yaml
102
+ # LLM Provider
103
+ provider: openai # or 'mock' for testing
104
+ model: gpt-4o-mini
105
+ api_key_env: OPENAI_API_KEY
106
+
107
+ # Analysis Thresholds
108
+ relevance_threshold: 0.55 # A1: Lower = more strict
109
+ divergence_threshold: 0.25 # A3: Lower = more strict
110
+ fact_check_threshold: 0.7 # A2: Higher = more strict
111
+
112
+ # Custom Keywords (optional)
113
+ misinformation_keywords:
114
+ - "conspiracy"
115
+ - "cover-up"
116
+
117
+ dangerous_keywords:
118
+ - "exploit"
119
+ - "malware"
120
+
121
+ # File Processing
122
+ skip_patterns:
123
+ - "**/.git/**"
124
+ - "**/node_modules/**"
125
+ ```
126
+
127
+ ### Mock Mode (No API Key Required)
128
+
129
+ SentinelRb includes a sophisticated mock mode for testing and development:
130
+
131
+ ```yaml
132
+ # .sentinel.yml
133
+ provider: mock
134
+ ```
135
+
136
+ The mock client provides:
137
+ - Pattern-based detection for all analyzers
138
+ - Simulated relevance scoring with built-in heuristics
139
+ - No external API calls required
140
+ - Consistent results for CI/CD pipelines
141
+
142
+ ### Output Formats
143
+
144
+ #### Table Format (Default)
145
+ ```
146
+ 📄 prompt.md
147
+ ❌ [A2] Prompt appears to instruct spreading of false information
148
+ ⚠️ [A1] Prompt contains potentially irrelevant information
149
+ ```
150
+
151
+ #### JSON Format
152
+ ```bash
153
+ sentinel_rb analyze --files prompt.md --format json
154
+ ```
155
+
156
+ #### Detailed Format
157
+ ```bash
158
+ sentinel_rb analyze --files prompt.md --format detailed
159
+ ```
160
+ ```yml
161
+ steps:
162
+ - uses: actions/checkout@v4
163
+ - uses: ruby/setup-ruby@v1
164
+ with: { ruby-version: 3.3 }
165
+ - run: gem install sentinel_rb
166
+ - name: Run Sentinel
167
+ env: { OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} }
168
+ run: |
169
+ sentinel --glob "prompts/**/*" --config .sentinel.yml --format table
170
+ ```
171
+
172
+ ## Architecture
173
+
174
+ SentinelRb consists of these key components:
175
+
176
+ - **Config**: Loads settings from `.sentinel.yml`
177
+ - **LLMClient**: Provides interfaces to OpenAI/Anthropic/custom models
178
+ - **Analyzers**: Pluggable modules that implement specific checks
179
+ - **Report**: Collects and formats results
180
+
181
+ ### Analyzer Structure
182
+
183
+ Each analyzer inherits from a base class and implements a `call` method:
184
+
185
+ ```ruby
186
+ class SentinelRb::Analyzers::Base
187
+ def initialize(prompt, config, client); end
188
+ def call # => [{id:, level:, message:}, ...]
189
+ end
190
+ ```
191
+
192
+ Example analyzer implementation:
193
+
194
+ ```ruby
195
+ class SentinelRb::Analyzers::UselessNoise < Base
196
+ def call
197
+ score = @client.similarity(@prompt, "core task description")
198
+ return [] if score >= @config['relevance_threshold']
199
+
200
+ [{
201
+ id: 'A1',
202
+ level: :warn,
203
+ message: "Average relevance #{score.round(2)} < threshold"
204
+ }]
205
+ end
206
+ end
207
+ ```
208
+
209
+ ## Key Benefits
210
+
211
+ - Focused exclusively on LLM inspection (not a Rubocop extension)
212
+ - File-based analysis of 5 hard-to-detect antipatterns
213
+ - Pluggable analyzer architecture
214
+ - Automated safety net for prompt modifications in CI pipelines
215
+
216
+ ## Development
217
+
218
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt.
219
+
220
+ ## Contributing
221
+
222
+ Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
223
+
224
+ ## License
225
+
226
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).