Gemini AI & Prompt Engineering Skill
This skill governs all AI-related logic within the TalentFilter platform, specifically focusing on the AIService in the backend.
1. Google Gemini API Integration
- •Model Versioning: Always use the most capable stable version (e.g.,
gemini-1.5-flashorgemini-1.5-pro) unless specific speed requirements dictate otherwise. - •Safety Settings: Configure AI safety settings via the
google-generativeaiSDK to ensure the AI doesn't refuse valid recruitment/screening tasks while maintaining professional boundaries. - •Async Execution: AI calls are high-latency; always use
awaitand ensure they are proxied through the FastAPI backend to avoid blocking the main thread.
2. Structured Output (JSON Mode)
- •Strict Schema: Every AI call must use a Pydantic model to define its response structure.
- •JSON Request: Set the
response_mime_typetoapplication/jsonin the Gemini config. - •Validation: Always wrap the AI parsing logic in a try-except block. If parsing fails, implement a retry mechanism or return a structured error response.
3. Advanced Prompt Engineering
- •System Instructions: Clearly define the AI's persona as an "Expert Technical Recruiter" or "Bias-Free Interviewer".
- •Chain-of-Thought: For complex tasks like grading interviews, use prompts that encourage step-by-step reasoning within the JSON output (e.g., a
reasoningfield before thefinal_score). - •Context Injection:
- •Job Analysis: Inject raw job description text + specific extraction goals.
- •Grading: Inject Question context + "Ideal Answer" + "Candidate Answer" + "Scoring Rubric".
4. Prompt Storage (Clean Code)
- •Separation: Never hardcode long prompts in Python files.
- •Storage: Store prompt templates in
backend/app/core/prompts/as.txtor.mdfiles. - •Template Engine: Use simple string formatting or Jinja2 to inject variables into prompts.
5. Cost & Performance
- •Token Optimization: Be concise in prompts. Avoid redundant instructions.
- •Caching: If similar requests are expected (e.g., re-analyzing the same job description), check for existing results in Supabase before calling the AI.