0Pricing
AI Agents with LangChain & Autonomous Workflows · درس

الضوابط الوقائية وسلوك الوكلاء الآمن

طبّق ضوابط وقائية عملية لسلامة وكلاء الذكاء الاصطناعي — مثل التحقق من المدخلات والمخرجات، وتصفية المحتوى، وتقييد الوصول إلى الأدوات — لمنع الإجراءات الضارة أو غير المقصودة.

الضوابط الوقائية وسلوك الوكلاء الآمن درس مجاني في AI Agents with LangChain & Autonomous Workflows على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Agents with LangChain & Autonomous Workflows، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

From Ethics to Engineering

Ethical principles need enforcement in code. Guardrails are the concrete controls that keep an agent within safe, intended boundaries at runtime.

They act on three points: the input, the model's reasoning, and the output or actions.

Input Guardrails

Check user input before it reaches the agent. Catch:

  • Prompt-injection attempts
  • Requests for disallowed topics
  • Personal data that should be redacted

Detecting Prompt Injection

Prompt injection tries to override your instructions (e.g. ignore previous rules). A simple guard flags suspicious phrases before processing.

BAD = ['ignore previous', 'disregard instructions']
if any(p in user_input.lower() for p in BAD):
    raise ValueError('Possible prompt injection')

Output Guardrails

Validate what the agent produces before showing it. Block unsafe content, leaked secrets, or off-policy answers, replacing them with a safe fallback message.

if contains_sensitive(answer):
    answer = 'I cannot share that information.'

Structured Output Validation

When an agent must return JSON, validate it against a schema. Reject or repair malformed output so downstream systems never receive bad data.

from pydantic import BaseModel

class Ticket(BaseModel):
    priority: str
    summary: str

Ticket.model_validate_json(agent_output)

Constraining Tool Access

The most dangerous actions come from tools. Give an agent only the tools it needs, and scope each one — read-only where possible, with limits on what it can affect.

Allowlists Over Blocklists

Define what is permitted rather than chasing every bad case. An allowlist of approved domains, tables, or operations is far safer than trying to enumerate everything to forbid.

ALLOWED_DOMAINS = {'docs.company.com'}
if domain not in ALLOWED_DOMAINS:
    raise PermissionError('Domain not allowed')

Moderation Models

Provider moderation endpoints classify text for harmful categories. Run inputs and outputs through them as an extra safety layer.

result = client.moderations.create(input=text)
if result.results[0].flagged:
    block()

Limiting Autonomy

Cap how much an agent can do unattended: max iterations, max tool calls, spending limits, and human approval for high-impact actions. Bounded autonomy prevents runaway behavior.

agent = create_agent(llm, tools, max_iterations=8)

Fail Safe, Not Open

When a guardrail is uncertain or a check errors, default to the safe choice — refuse or escalate — rather than letting the action through. A blocked safe request is better than an executed harmful one.

Logging and Review

Log every guardrail trigger. Reviewing these reveals attack patterns and false positives, letting you tune rules over time without weakening safety.

Quick Check

Test your guardrails knowledge.

Recap

You learned to engineer safe agent behavior:

  • Add input and output guardrails
  • Detect prompt injection and validate structured output
  • Constrain tool access with allowlists and scoping
  • Use moderation, limit autonomy, and fail safe
  • Log and review every trigger

Guardrails turn ethical intent into enforced, trustworthy agents.

الأسئلة الشائعة

هل درس «الضوابط الوقائية وسلوك الوكلاء الآمن» مجاني؟

نعم — نص درس «الضوابط الوقائية وسلوك الوكلاء الآمن» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Agents with LangChain & Autonomous Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.

ماذا ستتعلم في «الضوابط الوقائية وسلوك الوكلاء الآمن»؟

طبّق ضوابط وقائية عملية لسلامة وكلاء الذكاء الاصطناعي — مثل التحقق من المدخلات والمخرجات، وتصفية المحتوى، وتقييد الوصول إلى الأدوات — لمنع الإجراءات الضارة أو غير المقصودة. تتمرن على AI Agents with LangChain & Autonomous Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ AI Agents with LangChain & Autonomous Workflows؟

لا تُشترط خبرة سابقة. AI Agents with LangChain & Autonomous Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «الضوابط الوقائية وسلوك الوكلاء الآمن»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس AI Agents with LangChain & Autonomous Workflows هذا؟

نعم. كل درس في AI Agents with LangChain & Autonomous Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الاعتبارات الأخلاقية في وكلاء الذكاء الاصطناعي
  2. التحيّز والإنصاف والشفافية
  3. الاتجاهات والأبحاث الناشئة
  4. الضوابط الوقائية وسلوك الوكلاء الآمن
← العودة إلى AI Agents with LangChain & Autonomous Workflows